you can call the web service which is on same domain beacuse of some Security reasons.u will have to use JSON with padding (JSONP).
Your service has to return jsonp, which is basically javascript code. You need to supply a callback function to the service from your ajax request, and what is returned is the function call.
Example: 1
Ajax Request:
function hello() {
$.ajax({
crossDomain: true,
contentType: "application/json; charset=utf-8",
url: "http://example.example.com/WebService.asmx/HelloWorld",
data: {}, // example of parameter being passed
dataType: "jsonp",
success: jsonpCallback,
});
}
function jsonpCallback(json) {
document.getElementById("result").textContent = JSON.stringify(json);
}
Server-side Code:
public void HelloWorld(int projectID,string callback)
{
String s = "Hello World !!";
StringBuilder sb = new StringBuilder();
JavaScriptSerializer js = new JavaScriptSerializer();
sb.Append(callback + "(");
sb.Append(js.Serialize(s));
sb.Append(");");
Context.Response.Clear();
Context.Response.ContentType = "application/json";
Context.Response.Write(sb.ToString());
Context.Response.End();
}
Example:2 How can I produce JSONP from an ASP.NET web service for cross-domain calls?