![](/img/trans.png)
[英]Jquery ajax works in Chrome and Safari, but not in IE8 and Firefox
[英]jQuery ajax works in Chrome, but not in Firefox or Safari
我用jQuery
实现了ajax请求。 这是代码:
//initialize value, nameValue, emailValue
$.ajax({
url: "getPOST.php",
type: 'POST',
data: {
'id': value,
'name': nameValue,
'email': emailValue
},
success: function(response) {
console.log(response);
}
});
该代码在chrome中工作正常,但在Safari和Firefox中失败。 我已经看到了这个问题的一些答案,但是它们已经有6年或更长时间了。 解决此问题的方法可能是什么?
编辑:失败,我的意思是,在php端,在Firefox或Safari上运行时,数据库中没有存储任何内容,但它在Chrome中按预期工作。 控制台中没有错误消息。 Safari中的请求显示为红色,但未发送任何数据。
我检查了Firefox中的发布数据,并按原样检查了它们。 那里没有错误。 虽然请求被涂成红色。 这就是它的样子。 jQuery方面的错误?
在将用户定向到PayPal付款页面之前,我正在使用此代码将数据发送到我的服务器。
jQuery代码。 希望我没有删除很多括号。
// JavaScript Document
jQuery(document).ready(function($){
//you can now use $ as your jQuery object.
//real stuff here
$(".submit-link").click(function(e){
var value=$.trim($(".url-submit").val());
if(value.length>0){
value = encodeURIComponent(value);
var nameValue=$.trim($(".name-submit").val());
var emailValue=$.trim($(".email-submit").val());
if(nameValue.length>0){nameValue = encodeURIComponent(nameValue);}
if(emailValue.length>0){emailValue = encodeURIComponent(emailValue);}
$.ajax({
url: "getPOST.php",
type: 'POST',
data: {"id":value,"name":nameValue, "email":emailValue},
success: function(response) {
console.log(response);
}
//go to link in href now
});
}else{
var $urlSubmit = $('.url-submit');
$urlSubmit.addClass('invalid');
setTimeout(function(){
$urlSubmit.removeClass('invalid');
},500);
e.preventDefault();
}
});
//some other stuff
});
长时间等待评论,但是尝试排除jquery并尝试简单的xhr / fetch来查看是否可行(如果尝试获取,可能会收到其他可理解的错误)
fetch('getPOST.php', {
method: 'POST',
headers: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
body: 'id=0&name=bob&email=bob%40localhost'
}).then(res => console.log(res))
(野生动物园没有获取,所以尝试在Firefox中)
我唯一能做的是,您正在发布跨来源的网站...您要发布到同一域吗? 必须是网络错误/限制,因为您的代码有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.