Jump to content

Posting with json


Xtremer360

Recommended Posts

I"m trying to find out if this is really a PHP issue or jQuery issue.

 

After it does the POST request it sends this as a parameter:

 

username testusername

 

In the response I get this:

 

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

 

<h4>A PHP Error was encountered</h4>

 

<p>Severity: Warning</p>

<p>Message:  Missing argument 1 for Register::isUsernameAvailable()</p>

<p>Filename: controllers/register.php</p>

<p>Line Number: 118</p>

 

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

 

<h4>A PHP Error was encountered</h4>

 

<p>Severity: Notice</p>

<p>Message:  Undefined variable: username</p>

<p>Filename: controllers/register.php</p>

<p>Line Number: 120</p>

 

</div>{"username":"notfound"}

 

 

PHP

public function isUsernameAvailable($username)
{
        if ($this->usersmodel->isUsernameAvailable($username))
        {
            echo '{"username":"found"}';
        }
        else
        {
            echo '{"username":"notfound"}';
        }        
}

 

jQuery

$('#username').blur(function(){
        $.post('register/isUsernameAvailable', {"username":$(this).val()}, function(data){if(data.username == "found"){alert('username already in use');}}, 'json');
});

Link to comment
https://forums.phpfreaks.com/topic/263547-posting-with-json/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.