Jquery AJAX json - not called

Jquery AJAX json - not called

本文关键字:not called json AJAX Jquery      更新时间:2023-09-26

我无法连接到Web服务,尝试了很多不同的选项并更改了参数,提示在哪里挖掘?这是我第一次体验通过AJAX连接,我尝试通过其他客户端工作。

var xhr = $.ajax({
     url: webserUrl,
     type: "GET",
     data: JSON.stringify({ "Tabn": "1","Vaccurrent": "1","Vacnext": "1" }),
     cache: false,
     crossDomain: true,
     username: "user", 
     password: "password",
     processData: false,
     contentType: "application/json",
     dataType: "json",
     headers: {
        "Accept": "application/json; odata=verbose"
    },
     xhrFields: {
     withCredentials: true
                },
     crossDomain: true,
      success: OnSuccess, 
      error: OnError
        });
function OnSuccess(data, status) { alert(data); } function OnError(xhr, ajaxOptions, thrownError, request, error) { alert('xrs.status = ' + xhr.status + ''n' + 'thrown error = ' + thrownError + ''n' + 'xhr.statusText = ' + xhr.statusText + ''n' + 'request = ' + request + ''n' + 'error = ' + error); console.log('xrs.status = ' + xhr.status + ''n' + 'thrown error = ' + thrownError + ''n' + 'xhr.statusText = ' + xhr.statusText + ''n' + 'request = ' + request + ''n' + 'error = ' + error); }
});

错误:
xrs.status=200
抛出错误=未定义
xhr.statusText=确定
request=未定义
error=未定义

感谢大家的回答,更改为带有wsdl端点的url,还将内容类型更改为:"text/xml;charset=''"utf-8''",一切正常。

xrs.status = 200表示服务器接受了请求,因此问题可能发生在客户端,很可能是由"Accept": "application/json; odata=verbose"标头引起的,该标头指示jquery如果没有发送json作为响应,则拒绝服务器响应。

您需要使用浏览器提供的开发工具来检查服务器响应的数据。