Need help with the $.ajax() method
Hi,
I am new to jquery but I have tested it a little and I admit it is a very good library and it has reduced a lot of my code. On the other hand i am having a little trouble using $.ajax() method. Through this method I am unable execute a remotely located web service on every other browser except IE. A web service which is placed in the same folder is executed on all the browsers but a web service which is located on a separate domain or a remote location is not executed at all except of IE. Also the second problem that i am facing is that in the data header i am unable to pass a json variable. The following is the code which would give you some idea of what issues I am facing:
var jsonHost = {"domain" : window.location.hostname}; //json variable
//To store values returned from the web service.
var testService1= null;
var testService2= null;
var helloWorld = null;
//Calling a webservice located on the same domain/same folder. This service works on all browsers.
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "testservice.asmx/HelloWorld",
data: "{ }",
dataType: "json",
success: function(res) {
helloWorld = res.d;
alert(helloWorld);
},
error: function() {
alert("Web Service Failed to execute!");
}
});
//Calling a webservice located on the remote domain. This web service does not work on any browser except IE
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://www.someDomain.com/webservice.asmx/TestMethod1",
data: "{ domain :'localhost'}",
dataType: "json",
success: function(res) {
testService1= res.d;
alert("This is value of Test service 1 is: " + testService1);
}
});
Now the data that i have passed in the data header is hard coded the moment i write a variable such as jsonHost that i have initialized above instead of the hard coded values the code neither gives an error nor it works. In the second method the testMethod1 which is called from a remote location (i.e. my local testing web server) that web method does not do anything in all the browsers except IE. Help me out over as I have searched and tried a lot but due to my lack of experience in both java script and jquery I am stuck.