I somehow can't figure it out, the situation is as follows:
I'm calling a method on a web service that is not on the same machine and use the following JS snippet in my script:
$.ajax({
type: "POST",
url: "http://" + gServer + "/xawebservice/xawebservice.asmx/" + webMethod,
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
async: false,
data: WSParameters,
success: function callFunction(result) { processResults(result, pType, pParam1); },
error: function (xhr, status, error) {
alert(error.toString());
//alert(xhr.toString());
}
});
Parameters are fine and tested, the web method is also correct.
As an error message I get this:
Firefox: [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://localhost:7515/jquery-1.8.3.js :: :: line 8434" data: no]
Chrome: Error: NETWORK_ERR: XMLHttpRequest Exception 101
IE8: No Transport
If I'm using the same snippet on a web service that is running on the same machine, there is no problem. And if I use the remote web service over the web interface, it's also working fine.
PS: I googled around a bit and some pages were recommending some cross domain parameters, which didn't work either. Unfortunately using a relative path will not work I guess.
Thanks for any efforts in advance.
Br
vm370
UPDATE:
Alright I updated my code to execute a CORS request based on my existing one, but I get an error 500, executing the request on the server directly is working fine and CORS is activated on the server.
function xenappRequest(pType, pParam1) {
// CORS request
var url = "http://" + gServer + "/webservice/webservice.asmx/webMethod";
var params = { "appName": pParam1 };
var xhr = createCORSRequest("POST", url);
if (!xhr) {
alert('CORS not supported');
} else {
// Do the request
// Response handlers.
xhr.onload = function () {
//var text = xhr.responseText;
alert('Response from CORS request to ' + url + ': ' + xhr.response);
};
xhr.onerror = function () {
alert('Woops, there was an error making the request.');
};
xhr.send(JSON.stringify(params));
}
}
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
}
return xhr;
}
From FF i get the error 500, in IE8 the request lands in the xhr.onerror clause...
Any ideas?