0

enter code here有一个第三方 Web 服务 (soap) 从其网站中的搜索返回值。我可以使用包含搜索参数的普通旧 URL 调用此服务。前任。城市、州或邮编。此服务返回格式良好的 XML 字符串。

问题是......使用Javascript,我可以毫无问题地调用服务/ URL。

但回调失败。显示的消息指示解析错误。

使用 firefox 和 firebug,我可以看到结果被正确返回,只是在普通的旧 XML 中。

似乎 ajax 回调正在尝试解析结果,但它失败了。

该第三方位于完全不同的网站上,因此确实适用跨站点脚本规则。

所以问题是......

1)有没有办法不执行解析,只得到结果?2) 是否有任何额外的参数可以调整以允许我查看和处理结果集?

这是我正在使用的代码...

  function LoadMenu() {
    varType = "GET";
    varUrl = "https://www.xxxx.com/soap/352mg/xml.php?callback=?";
    varData = { zip: 68105 };
    varContentType = "text/xml; charset=utf-8";
    varDataType = "jsonp";
    varProcessData = false;
    $.ajax({
      crossdomain: true,
      type: varType, //GET or POST or PUT or DELETE verb
      url: varUrl, // Location of the service
      data: varData, //Data sent to server
      contentType: varContentType, // content type sent to server
      dataType: varDataType, //Expected data format from server
      processdata: false, // varProcessData, //True or False
      success: function (msg) {//On Successfull service call
        serviceSucceeded(msg);
      },
      error: ServiceFailed// When Service call fails
    });
  }
4

1 回答 1

0

JSONP 是一种跨域限制的 hacky 解决方案,它在 html 中包含一个新的脚本标签,因此浏览器会自动解析 src。您不能禁用它。

如果您需要获取 XML 并且他们不提供 JSONP 或某种跨域请求(如 CORS),那么您将需要设置代理。通过设置代理,您可以使用其他方式(如 PHP)获取数据,然后将其重新路由到您域上可能需要它的任何页面。

于 2012-10-16T19:55:52.130 回答