简体   繁体   中英

jquery post on document ready

All i want is, a data will pass into this php file: check.php and this php file will pass data into that function when the page is ready. this is just an expirement.

ok I have this code:

$(document).ready(function() {
    $.post("check.php", {
        name: "log"
    }, function(data) {
        if (data === "yes") {
            alert('has been login');
        } else {
            alert('has not login');
        }
    });
});​

and i have this php code ("check.php") where the jquery post will pass the data into.

<? //check
$chk = $_POST['name'];

if (isset($chk === "log")) {
    if (isset($_COOKIE['admin'])) {
        if ($_COOKIE['admin'] === "login") {
            echo "yes";
        }
    } else {
        echo "no";
    }
} else {
    echo "no";
}
?>

but nothing happen, even i change the whole code in check.php into: "echo "yes";" theres nothing happen, i guess, its either there is no data receive or there is no data pass. Hope someone could help me into this simple and cute problem that im stuck with. thank you in advance

I think you missed a closing brace. This just works as expected:

 $.post('check.php', { name: 'log' }, function(data) { 
     if (data === "yes") 
      { 
         alert ('has been login'); 
       } 
       else 
     { 
     alert ('has not login'); 
     } 
  });

Run this JSFiddle http://jsfiddle.net/S53k5/ and you will see the call passing by in Fiddler.

我猜这是因为你使用标题“name”,这是一个保留关键字。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM