0

我正面临从 QlikView 自定义对象对 Web 服务进行 jQuery ajax 调用的问题。ajax 调用成功地从浏览器以及从 Fiddler 和 POSTMAN 到 Web 服务工作。

在检查 Fiddler 后,我发现请求是“OPTION”而不是“GET”。响应为 200 OK,但未调用 Web 服务方法。感谢这方面的任何帮助。

$.ajax({
    cors: true ,
    beforeSend: function (xhr) {
         xhr.setRequestHeader('Content-type','appliction/json; charset=utf-8');
         xhr.setRequestHeader('crossDomain',true);
         xhr.setRequestHeader('cors', true );
         xhr.setRequestHeader('Access-Control-Allow-Origin', 'http://qlikview');
         },
    url: "http://localhost:56915/DBWrite/DBWriteMainService.svc/TestService",
    type: "GET",
    cache: false,
//data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
crossDomain: true, 
dataType: "JSON",
//processData: false,
xhrFields: { withCredentials: true },
success: function (response) { alert(response);},
//failure: function (errorMsg) {alert("error"+errorMsg);} 
error: function (xhr, status, error) { 
var errorMessage = xhr.status + ': ' + xhr.statusText;
alert('Error - ' + errorMessage);}
});

来自 Fiddler 的请求标头:

OPTIONS /DBWriteMainService.svc/TestService?_=1620838978068 HTTP/1.1
Accept: */*
Origin: http://qlikview
Access-Control-Request-Method: GET
Access-Control-Request-Headers: content-type, accept, crossdomain, cors, access-control-allow-origin
UA-CPU: AMD64
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Win64; x64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; wbx 1.0.0; wbxapp 1.0.0; Zoom 3.6.0)
Host: localhost:56915
Content-Length: 0
Connection: Keep-Alive
Pragma: no-cache

来自 Fiddler 的响应标头:

HTTP/1.1 200 OK
Server: Microsoft-IIS/10.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Authorization, Origin, Content-Type, Accept, X-Requested-With
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcc21haGFwYTNcT25lRHJpdmUgLSBBbmFsb2cgRGV2aWNlcywgSW5jXERlc2t0b3Bcd2JcREJXcml0ZVRlc3RcREJXcml0ZVRlc3RcREJXcml0ZU1haW5TZXJ2aWNlLnN2Y1xUZXN0U2VydmljZQ==?=
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Date: Wed, 12 May 2021 17:03:12 GMT
Content-Length: 0
4

0 回答 0