简体   繁体   English

XML解析错误:未找到元素jQuery ajax中的位置错误

[英]XML Parsing Error: no element found Location error in jQuery ajax

I am trying to call cross-domain rest service using jquery as my code below: 我正在尝试使用jquery作为以下代码来调用跨域Rest服务:

$.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8"});
   var newUrl =  "http://127.0.0.1:1338/app?restUrl=" + encodedURL; //dynamic url
    $.getJSON(newUrl, function(result){
    //response data are now in the result variable
    alert("inside");
    alert(result);
});

But when I try to execute in mozilla, I am getting this error in Firebug. 但是,当我尝试在mozilla中执行时,我在Firebug中收到此错误。

XML Parsing Error: no element found Location: moz-nullprincipal:{f8dedba7-d539-45da-a5aa-53d5ae919084} Line Number 1, Column 1: XML解析错误:找不到元素位置:moz-nullprincipal:{f8dedba7-d539-45da-a5aa-53d5ae919084}行号1,列1:

But status I am getting in Firebug as: 但是我在Firebug中的身份是:

GET http://localhost:1338/app?restUrl=http://localhost:9090/Bank2/service/helloRest/greet GET http://localhost:1338/app?restUrl=http://localhost:9090/Bank2/service/helloRest/greet

200 OK 6ms jquery.min.js (line 18) 200 OK 6ms jquery.min.js(第18行)

Because of that error, I am not able to get alerts inside getJson. 由于该错误,我无法在getJson内获取警报。 Can anyone please guide me? 谁能指导我?

Because it's cross domain, you probably have to use JSONP 因为它是跨域的,所以您可能必须使用JSONP

JSONP JSONP

If you are getting the above error in firebug, you are most probably making a cross browser request that is not allowed and not having invalid XML in your response. 如果您在萤火虫中遇到上述错误,则很可能是您提出了一个跨浏览器请求,该请求是不允许的,并且响应中没有无效的XML。 Cross browser requests are not allowed, unless you use jsonp or script as the data type. 除非您使用jsonp或脚本作为数据类型,否则不允许跨浏览器请求。

Error explanation 错误说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM