我是无法从阿贾克斯的响应。请指导我如何解决这个错误,我收到来自我在捣鼓网络调试器并仍然AJAX是示值误差签服务器成功的数据回报。 XML解析错误:没有元素发现地点:MOZ-nullprincipal:{6b0a1ac2-50ab-4053-9f71-8ae49202288d} 1号线,1列:的
$ j.ajax({
键入:POST,
网址:HTTP://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit,
数据:摄氏= 12',
跨域:真正的,
异步:假的,
成功:函数(响应)
{
警报(成功全部完成+ response.string);
},
beforeSend:功能(XHR){
xhr.overrideMimeType('text / plain的;字符集= UTF-8);
}
});
解决方案
我有这个问题的请求:
$。阿贾克斯({
键入:POST,
网址:ajaxUrl,
数据类型:JSON,
的contentType:应用/ JSON
数据:JSON.stringify(数据),
成功:功能(数据){
...
}
});
在接受请求标题是:
接受应用程序/ JSON,文字/ javascript中,* / *; Q = 0.01
响应状态是200,但浏览器检测到错误,并没有成功的回调名为
人删除的dataType修正:JSON:
$。阿贾克斯({
键入:POST,
网址:ajaxUrl,
的contentType:应用/ JSON
...
这是接受标题中要求的唯一区别改为:
接受* / *
但现在的成功回调被调用。
i am unable to get the response from ajax. please guide me how to resolve this error, i am getting successful data return from the server i have checked it in fiddle web debugger and still ajax is showing error. XML Parsing Error: no element found Location: moz-nullprincipal:{6b0a1ac2-50ab-4053-9f71-8ae49202288d} Line Number 1, Column 1:
$j.ajax({
type:"POST",
url:'http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit',
data: 'Celsius=12',
crossDomain:true,
async: false,
success:function(response)
{
alert("Success Full Done"+response.string);
},
beforeSend: function( xhr ) {
xhr.overrideMimeType( 'text/plain; charset=UTF-8' );
}
});
解决方案
I've this problem with request:
$.ajax({
type: "POST",
url: ajaxUrl,
dataType : "json",
contentType: "application/json",
data: JSON.stringify(data),
success: function (data) {
...
}
});
Accept header in request is:
Accept application/json, text/javascript, */*; q=0.01
Response status is 200, but browser detect error and no success callback called
Fixed by remove dataType : "json":
$.ajax({
type: "POST",
url: ajaxUrl,
contentType: "application/json",
...
The only difference that accept header in request changed to:
Accept */*
But now success callback is called.