I am new to webservice and ajax .. I tried to call a webservice using POST method. I tried to invoke it using Postman (Google chrome App) and I was getting the response but when I tried using Ajax I am getting error Following are the things I did:
My Code: (I wrote a JS in which I included following code and tried all the commented options too ):
$.ajax({
crossDomain: true,
url : 'https://yxyxyxyxyx/search/v1/query.json',
type : 'POST',
dataType : "json",
data: {appId: "a9b475a079",query: "dhcp"},
//async : true,
//headers: {"Content-type": "application/json"},
headers: { 'Access-Control-Allow-Origin': '*' },
//contentType: "application/json; charset=utf-8",
//headers: ('Access-Control-Allow-Methods: GET, POST, OPTIONS'),
//headers: ('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With'),
//headers: ('Access-Control-Allow-Credentials: true'),
// Access-Control-Allow-Origin: "http://localhost:8080",
// headers: { 'Access-Control-Allow-Origin': '*' },
//userAgent : 'Mozilla/22.0',
success: function(data){
alert("hi success");
},
error: function(data) {alert("An error occured: " + data.status + " " + data.statusText);
});
I am getting the alert in the error and getting following error while debugging:
XMLHttpRequest cannot load https://www.sample.search/v1/query.json. The request was redirected to 'https://www.sample/obrareq.cgi?wh%3DCCI-STG4%20wu%3D%2Fuesps%…n-tools-stage.cisco.com%20ru%3D%252Fuesps%252Fsearch%252Fv1%252Fquery.json', which is disallowed for cross-origin requests that require preflight.
I tried all the options to resolve the CROS option in which I found on net… do we have any other way to resolve it.
Can someone help me if we can do it using a java class that will also serve the purpose