I'm using jQuery's $.ajax
function to submit a form, which works, but the success is where I'm having my problem. Here is my code:
$("#form").submit(function () {
$.ajax({
type: "POST",
url: '/login/spam',
data: formData,
success: function (dataCheck) {
if (dataCheck == 'value') {
//Do stuff
}
}
});
return false;
});
The problem I'm having is the if
function keeps saying that dataCheck doesn't equal value. I know that it does, because when I remove return false;
the page displays value, as expected. Also, I have used an almost identical code before, which works. Could somebody give me some advice?
$. ajax({ url: "page. php", data: stuff, success: function(response){ console. log("success"); } });
ajax function is deprecated.
jQuery uses ajax for many of its functions, but it nothing else than a library that provides easier functionality. With jQuery you dont have to think about creating xml objects ect ect, everything is done for you, but with straight up javascript ajax you need to program every single step of the ajax call.
Ajax (Asynchronous JavaScript and XML) is now long gone from the developer vernacular, along with other JavaScript technologies of that early Web 2.0 era. But jQuery has stood the test of time. Indeed, up till very recently, it was still growing year-over-year.
How to find the answer yourself:
Place a debug code to see what you get from the server.
$("#form").submit(function () {
$.ajax({
type: "POST",
url: '/login/spam',
data: formData,
success: function (dataCheck) {
console.log(dataCheck); // <==============================
if (dataCheck == 'value') {
//Do stuff
}
}
});
return false;
});
It will probably be in other format than you think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With