跨域Ajax调用没有找到元素位置:moz-nullprincipal [英] Cross-domain Ajax call gets no element found Location: moz-nullprincipal

查看:213
本文介绍了跨域Ajax调用没有找到元素位置:moz-nullprincipal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过jquery调用 $调用跨域Web服务ajax()服务返回

 <?xml version =1.0encoding =utf-8?> 
< double xmlns =http://www.webserviceX.NET/> 1.4248< / double>

如果我指定dataType xml(或者没有指定任何内容 - jquery猜测正确),我得到 XML解析错误:找不到元素位置:moz-nullprincipal:{4030734c-b902-4251-9067-1d1b5b15fc72}行号1,第1列:错误从服务)。但是,如果我指定dataType jsonp 脚本 - 我可以看到在firebug一切都回来正确;但是jquery显然试图对结果求值并给出相应的错误(缺少分号或类似的)。



在jQuery中有一种方法来启用跨域调用


  1. strong>知道,备用选项是调用服务器上调用Web服务并将结果返回浏览器的程序;

  2. 我指定crossDomain:true。它似乎没有任何区别。

  3. 错误函数确实被调用。

跨域ajax是只允许使用JSONP而不是XML



在JQuery 1.5中,他们添加了 crossDomain:true 参数, code>?callback => 的值到 url 。如果设置该参数,还必须设置 dataType:'json'。跨网域网址还必须支持JSONP并提供您的预期数据。


I am trying to invoke a cross-domain web service through jquery call $.ajax() The service returns

<?xml version="1.0" encoding="utf-8"?>
<double xmlns="http://www.webserviceX.NET/">1.4248</double>

If I specify dataType xml (or not specifying anything - jquery guesses correctly), I am getting XML Parsing Error: no element found Location: moz-nullprincipal:{4030734c-b902-4251-9067-1d1b5b15fc72} Line Number 1, Column 1: error (looks like nothing is coming back from the service). However, if I specify dataType jsonp or script - I can see in firebug that everything is coming back correctly; however jquery apparently tries to eval the results and gives me corresponding error (missing semicolon or similar).

Is there a way in jQuery to enable cross-domain call and not evaluate it?

Notes:

  1. I know that the fallback option is to call a program on my server that will invoke the web service and return the result to the browser;
  2. I did specify crossDomain: true. It doesn't seem to make any difference.
  3. "error" function does get invoked. But instead of original value "data" contains "parseerror".

解决方案

Cross domain ajax is only allowed for JSONP, not XML

In JQuery 1.5 they added the crossDomain:true parameter which simply appends a ?callback=> value to the url. If you set that parameter, you must also set dataType:'json'. The cross-domain URL must also support JSONP and be serving up your expected data as such.

这篇关于跨域Ajax调用没有找到元素位置:moz-nullprincipal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆