来自 QlikView 扩展对象的 jquery ajax 请求发送 OPTION 而不是 GET在 Fiddler 中检查

问题描述

我在从 QlikView 自定义对象对 Web 服务进行 jQuery ajax 调用时遇到问题。 ajax 调用成功地从浏览器以及从 fiddler 和 POSTMAN 到 Web 服务。

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

$.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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)