I wrote a WCF library and put it on a server (IIS7). I can reach its folders and its contents by browsing a URL like "foo.com/test.asmx" and its methods can be seen as "foo.com/test.asmx/MyMethod"
When I browse a page in the same application on server(servers's local) and send request to the method by using URL "foo.com/test.asmx/MyMethod" I get the result correctly.
But when I browse the same html page in my local computer and send the same request to the URL "foo.com/test.asmx/MyMethod" the ajax request fells in error state. (In addition to that, it works correctly on localhost in my computer)
I think I cannot reach the method or get results out of local server.
My ajax call:
var loginInfo = "{ 'username': '" + encodeURIComponent($("#lUsername").val()) + "', 'password': '" + encodeURIComponent($("#lPassword").val()) + "', 'uuid': 'asd'}";
$.ajax({
type: "POST",
//async: false,
crossDomain: true,
url: "http://foo.com/test.asmx/MyMethod",
data: loginInfo,
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (msg) {
var myJsonObj = $.parseJSON(msg.d);
if (myJsonObj.userLoggedIn == 1) {
insertLoginToDB(myJsonObj.username, myJsonObj.userEmail, myJsonObj.userDeviceUuid);
$.mobile.changePage("#homePage", { transition: "none" });
}
else {
alert("Unsuccessful login. Try again.");
}
},
error: function (msg) {
alert("Error!");
}
});
How can I fix the problem? What causes this kind of error?