简体   繁体   中英

PHP Script Not Receiving POST Variable sent by JQuery

Here's the code (already imported the JQuery):

$.post("check.php", { username: usr },
    function(result)
    {
        //if the result is 1
        if(result == 1)
        {
            //show that the username is available
            $('#ck_usr_rslt').html(username + ' is Available');
        }
        else
        {
            //show that the username is NOT available
            $('#chk_usr_rslt').html(username + ' is not Available');
        }
});

The thing is, my check.php script keeps throwing the following error:

PHP Notice:  Undefined index: username in /Applications/MAMP/htdocs/RP/check.php on line 23

(Line 23 is when is calls $_POST['username'])

So what's wrong? Could it be the local server I'm running that's the problem? Or is it just some mistake of mine in the JavaScript?

看来“ usr”变量为空(这是JavaScript而不是php),您能否向我们展示如何检索该变量?

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