【问题标题】:Call Webservice with jQuery Ajax使用 jQuery Ajax 调用 Web 服务
【发布时间】:2013-11-13 13:35:27
【问题描述】:

我正在尝试使用 jquery.ajax 调用我的网络服务。

jQuery.support.cors = true;
    $.ajax({
        type: 'POST',
        url: wsUrl,
        contentType: "text/xml; charset=utf-8",
        dataType: "xml",
        cache: false,
        crossDomain: true,
        data: soapRequest,
        success: reqSuccess,
        error: reqError
    });

我得到“拒绝访问”-错误和状态/readyState 0。

如果我使用 SoapUI 向我的 Web 服务发出请求,它会很好地工作。

【问题讨论】:

    标签: jquery ajax web-services access-denied


    【解决方案1】:

    发出 SOAP 请求时,请确保将 processData 设置为 false,以防止 jQuery 将您的 XML 请求转换为字符串。

    $.ajax({
        type: 'POST',
        url: wsUrl,
        contentType: "text/xml; charset=utf-8",
        dataType: "xml",
        cache: false,
        crossDomain: true,
        data: soapRequest,
        processData: false,
        success: reqSuccess,
        error: reqError
    });
    

    来自文档:http://api.jquery.com/jQuery.ajax/

    processData (default: true)
    Type: Boolean
    By default, data passed in to the data option as an object (technically, anything 
    other than a string) will be processed and transformed into a query string, fitting 
    to the default content-type "application/x-www-form-urlencoded". If you want to send 
    a DOMDocument, or other non-processed data, set this option to false.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 2015-01-03
      • 1970-01-01
      相关资源
      最近更新 更多