Reputation: 40
So here is the ajax call that is making the problem
$.ajax({
type: "POST",
url: "src/login.php",
dataType: "JSON",
data: {username: usr, password: pwd},
success: function(json){
loggedStatus=json.status;
alert(json.status);
}
});
It is succesfully passing the variables to the php file, but it isn't entering th success: part. This is example of what the php file returns
{
"status": "Wrong"
}
or
{
"status": "154414707fe8d22bb6239648ce11a9c9bede1a3e"
}
Which is totaly fine.
Upvotes: 0
Views: 80
Reputation: 56
Remove the dataType
$.ajax({
type: "POST",
url: "src/login.php",
data: {username: usr, password: pwd},
success: function(result){
var json = jQuery.parseJSON(result);
alert(json.status);
}
});
Upvotes: 1
Reputation: 1894
Also, try typing json
instead of JSON
in the dataType.
Avoid using success
.
From the jQuery website :
Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
A bit surprised to see this example on the jQuery ajax page :
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
Upvotes: 2
Reputation:
Try putting the url as the first parameter in your $.ajax({ function.
because the syntax is: $.ajax(url[, options])
Upvotes: 1