gpt4 book ai didi

javascript - jQuery 的 AJAX 请求不起作用

转载 作者:行者123 更新时间:2023-11-28 12:42:07 25 4
gpt4 key购买 nike

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 中在 Debug模式下执行时运行完美,否则它不会返回任何内容。

执行时,它会显示警报框,其中没有任何内容。我在控制台的 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 });

关于javascript - jQuery 的 AJAX 请求不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11440608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com