gpt4 book ai didi

javascript - Ajax 调用在 Firefox 中似乎失败

转载 作者:行者123 更新时间:2023-11-28 05:29:55 25 4
gpt4 key购买 nike

我目前正在开发一个项目,在该项目中,我使用 Ajax 调用将数据从 JavaScript 发送到 PHP 脚本。我试图在 Stackoverflow 上寻找答案,但没有成功,因此我提出了一个问题。

此代码在我的 Chrome 浏览器上运行正常,但在 Firefox 或 Safari 中尝试时失败。

$.ajax({
method: "POST",
url: "index.php?option=com_lowbudgetrestvisual&task=sdc.connect&format=json",
cache: false,
data: {
data: data
},
success: function(data, http, state) {},
error: function(http, state, error) {
console.log("Response -> failed");
console.log("http : " + http);
console.log("state: " + state);
console.log("error: " + error);
}
});

编辑:每当我尝试控制台登录 google chrome ,只是说Response -> success 。当我尝试登录 Firefox 时,我收到以下文本。

Response -> failed
http = [object Object]
state = error
error =

编辑2:我正在制作form然后提交至PHP script将其保存在database中使用 PHP。另ajax调用以表单形式进行,确保将电子邮件发送给表单中的用户和管理员。我如何确保两者都能正常工作是通过以下 JavaScript 代码:

    $('#sdc').on("click", function(e) {

e.preventDefault();

{{ then some codes and the ajax call }}

});

$('#sdc').on("click", function() {
$("#userForm").submit();
});

编辑3:我尝试了console.log("http : " , http);这就是我在控制台中得到的内容:

    http = Object {
readyState: 0,
getResponseHeader: .ajax / v.getResponseHeader(),
getAllResponseHeaders: .ajax / v.getAllResponseHeaders(),
setRequestHeader: .ajax / v.setRequestHeader(),
overrideMimeType: .ajax / v.overrideMimeType(),
statusCode: .ajax / v.statusCode(),
abort: .ajax / v.abort(),
state: .Deferred / d.state(),
always: .Deferred / d.always(),
then: .Deferred / d.then(),
11 more…
}

最佳答案

这段代码在 Firefox 中对我来说工作得很好。请检查 Firefox 浏览器版本和 jquery。另请检查服务器 php 文件路径。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$.ajax({
method: "POST",
url: "test1.php",
cache: false,
data: {
data: 'test'
},
success: function(data, http, state) {},
error: function(http, state, error) {
console.log("Response -> failed");
}
});

</script>

关于javascript - Ajax 调用在 Firefox 中似乎失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39787503/

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