A simple approach would be to use JSONP in your ajax calls, as shown below:
$.support.cors = true;
$.ajax({
type: "POST",
crossdomain: true,
contentType: "application/json; charset=utf-8",
url: ServiceURL,
dataType: "jsonp",
data: { Param1 : 'Test'},
success: function (data) {
}
and your handler will look like this:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "application/json";
string callback = context.Request.QueryString["callback"];
string Param1 = context.Request.QueryString["Param1"];
object dataToSend = null;
JavaScriptSerializer js = new JavaScriptSerializer();
string JSONstring = js.Serialize(dataToSend);
string JSONPstring = string.Format("{0}({1});", callback, JSONstring);
context.Response.Write(JSONPstring);
}
the above code converts the response to JSONP. callback parameter is automatically added by ajax call and should be returned to the client
source
share