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.
Below is a working example.
ajax request:
$.ajax({
crossDomain: true,
type:"GET",
contentType: "application/json; charset=utf-8",
async:false,
url: "http://<your service url here>/HelloWorld?callback=?",
data: {projectID:1},
dataType: "jsonp",
jsonpCallback: 'fnsuccesscallback'
});
server side code returning jsonp (c#):
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();
}
Refer What is JSONP all about?.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…