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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.