0

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.

8
  • Is there an error in the console when this runs (or anything at all helpful)? Jan 11, 2015 at 13:58
  • console.log(json) in your success and see what it returns.
    – user1897253
    Jan 11, 2015 at 14:00
  • Nope nothing @Nathan Taylor Jan 11, 2015 at 14:01
  • The console stays empyty @Koen Jan 11, 2015 at 14:02
  • is the url you are using right?, also try putting the url as the first line after $.ajax({.
    – user1897253
    Jan 11, 2015 at 14:03

3 Answers 3

2

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 );
});
1

Try putting the url as the first parameter in your $.ajax({ function.

because the syntax is: $.ajax(url[, options])

1

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);
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.