AJAX请求不工作
问题描述:
function showDialog(link) {
$('#dialog .newsletter-join').click(function() {
email = $.trim($(this).parent().find('.email').val());
if (email != "Email Address" && email.length > 5) {
$.ajax({
url: '/newsletter/join',
data: {
'email': email,
'pid': $('#dialog .pid').html().trim()
}
});
return true;
}
return false;
});
}
在FF正确执行这个代码,并在Chrome它时,在调试模式下执行运行完美,其他明智它不返回任何东西。AJAX请求不工作
执行时,它显示没有任何内容的警报框。我也没有在控制台的XMLHttp响应中看到任何内容。 我尝试了一些其他的变化:
cache:false // It just exeutes for the first time
datatype:html
可否请你让我知道如何追踪这个问题?
更新的代码:
我使用下面的脚本
$(document).ready(function() {
// $(window).load(function() {
showDialog();
return true;
//});
});
function showDialog(link) {
$('#dialog .newsletter-join').click(function() {
email = $.trim($(this).parent().find('.email').val());
if (email != "Email Address" && email.length > 5) {
$.ajax({
url: '/newsletter/join',
data: {
'email': email,
'pid': $('#dialog .pid').html().trim()
},
success: function(data) {
alert("Suvvess" + data);
},
error: function(xmlHttpRequest, textStatus, errorThrown) {
alert("error" + errorThrown);
}
});
return true;
}
return false;
});
}
最新的代码改变调用代码: 我加入了
async: false
这种变化在Ajax调用给预期的结果,但这将停止所有脚本执行,所以仍然觉得这不能成为永久解决方案
答
你应该错误后关闭AJAX功能
$.ajax({
url:'/newsletter/join',
data:{ 'email':email, 'pid':$('#dialog .pid').html().trim() }
>>>HERE REMOVE IT });
你'成功:'行是'$ .ajax'外呼。 – bhamlin 2012-07-11 20:09:17
对不起,这是我的一个错字。我只是想看看我是否得到任何xmlhttpresponse,即使我拿出来的代码行为仍然是相同的 – KAPILP 2012-07-11 20:18:29
@KAPILPATIL:你能发布你的更新代码吗? – 2012-07-11 20:23:25