Jquery get array details
- by Matt
I'm having trouble getting a response back from a Jquery ajax call...
(It's a script to authenticate a user, and needs to return their name and user ID. My understanding was that I could encode it as JSON and get the data in the format below.
It is returning an error of "undefined" for the alert().
The javascript
$.ajax({
type: "POST",
url: "myURL.php",
data: {username: username, password: password},
success: function(results) {
//THIS IS WHERE THE PROBLEM IS
alert('Hi '+results.name); //Should be "Hi Basil Fawlty"
}
});
The PHP (myURL.php)
//This comes from a SQL call that returns the following name
json_encode(array(
'id'=>1,
'name'=>'Basil Fawlty'
));
Any help or ideas on where I am going wrong would be greatly appreciated!
Thanks.