jquery ajax中的响应状态为"0" [英] Response status is '0' in jquery ajax
问题描述
我正在使用jquery ajax在数据库中存储数据.我通过URL调用服务,并通过以下方式将数据发送给它:
I'm using a jquery ajax for storing a data in the database. I call a service through a url and send data to it in the following way:
$.ajax({
type: "POST",
url: "http://192.168.250.118:8080/rest_service/rest/user",
data: JSON.stringify({ "loginName": "tsample@gmail.com", "mobile": "1234567890" }),
async: false,
contentType: "application/json",
crossDomain: true,
success: function(data){
alert("success");
},
error: function(XMLHttpRequest, textStatus, errorThrown){
console.log(XMLHttpRequest);
console.log(textStatus);
console.log(errorThrown);
}
});
执行此操作时,出现此错误:
When I execute this, I get this error:
{"readyState":0,"status":0,"statusText":"error"}
这是我在网络中查找错误时得到的:
This is what I get when I look for errors in network:
但是,如果我尝试使用邮递员,则会存储数据,并且会得到200OK
响应.上面的代码有什么问题?我应该改变什么?
But, if I try using postman, the data is getting stored and I get 200OK
response. What's wrong with the above code? What should I change?
推荐答案
在发送之前对数据进行字符串化-data: JSON.stringify({ "loginName": "tsample@gmail.com", "mobile": "1234567890" })
amd contentType:"application/json"
Stringify the data before sending - data: JSON.stringify({ "loginName": "tsample@gmail.com", "mobile": "1234567890" })
amd contentType:"application/json"
这篇关于jquery ajax中的响应状态为"0"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!