jquery ajax request from QlikView extension object sends OPTION instead of GET (checked in Fiddler)

75 Views Asked by At

I'm facing an issue making jQuery ajax call to a webservice from QlikView custom object. The ajax call successfully works from a browser and also from Fiddler and POSTMAN to the web service.

Upon checking Fiddler I found that the request goes as "OPTION" instead of "GET". The response comes as 200 OK but the webservice method is not invoked. Appreciate any help in this regard.

$.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);}
});

Request Header from 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

Response Header from 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
0

There are 0 best solutions below