报错:
No 'Access-Control-Allow-Origin' header is present on the requestedresource. Origin 'http://127.0.0.1:8020' is therefore not allowed access. The response had HTTP status code 503.
方法:
$.ajax({
type:"post",
url:dataUrl.addDeliveraddress,
dataType:"json",
data:str,
statusCode:{
200:function(data){
alert("成功");
},
404:function(data){
alert("404");
},
503:function(){
alert("添加失败");
},
}
});
只能判断200或者404,503跟本抓取不到求解决
这是报的跨域错误
用success和error来试试,503是没有响应了,没遇到过503的情况,可能会触发ajax timeout,不知道直接用error能不能捕捉到,有答案也告知我吧?
用complete 当请求完成之后调用这个函数,无论成功或失败。传入 XMLHttpRequest 对象,以及一个包含成功或错误代码的字符串。
这个是跨域了。
你可以用
dataType:jsonp
服务器返回个callback=?
或者
服务器返回时设置下header的Access-Control-Allow-Origin 来源 Access-Control-Allow-Methods 允许的方法 (POST GET PUT...) Access-Control-Allow-Credentials: true,
我用的zepto,我这样判断:
除了状态码以外,它的报错的message也可以作为判断依据