简体   繁体   中英

JQuery $.post() callback failure

Here's my JavaScript Code:

$.post("Actions.php", {
    'recaptcha': grecaptcha.getResponse(),
    'email': $("#emailInput").val(),
    'Password': $("#passwordConfirm").val(),
},
function(data) {
    console.log(data);
})

Now the post request was successfully executed, but console.log(data) was ignored by JQuery. I tried to search for any possible errors from the documents,but nothing found. Anything wrong with my code? Thanks.

When providing a success , JQuery probably parses your POST data/body object as its settings object instead

It should work if you move the callback to a .done

edit: mis-read the jQuery.post documentation , ignore the above

Try adding a handler for both done and fail:

$.post("Actions.php", {
    'recaptcha': grecaptcha.getResponse(),
    'email': $("#emailInput").val(),
    'Password': $("#passwordConfirm").val(),
})
.done(function(data, textStatus, jqXHR) {
    console.log("Success ", data);
})
.fail(function(data, textStatus, jqXHR) {
    console.log("Failed ", textStatus);
});

.done is run on a 'successful' response, .fail for failure responses, and .always for any response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM