jQuery AJAX成功 [英] jQuery AJAX Success
问题描述
我正在使用jQuery的$.ajax
函数提交可以正常工作的表单,但是成功是我遇到问题的地方.这是我的代码:
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;
});
我遇到的问题是if
函数不断说dataCheck不等于 value .我知道是的,因为当我删除return false;
时,页面按预期显示 value .另外,我之前使用了几乎相同的代码,这行得通.有人可以给我一些建议吗?
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?
推荐答案
如何自己找到答案:
放置调试代码,以查看您从服务器获得的信息.
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.
这篇关于jQuery AJAX成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!