parsererror after jquery.ajax request with jsonp content type

When we make a cross domain call through jquery $.ajax method through jsonp request then often this error occurs 'jQuery1510993527567155793_137593181353 was not called parsererror' function name can vary as it is randomly generated by jquery.

request failed parsererror error jquery was not called 

request failed parsererror error jquery was not called
  request failed parsererror error jquery was not called
Explanation :
when you are using jsonp as datatype (making cross domain request) Jquery generate random function and append is to requested url as a querystring named callback (callback=?), you need to append response json data as a parameter of this function as given below -

url : http://www.dotnetbull.com/cross-domain-call.ashx?ref=jquery-jsonp-request
url call by ajax :
http://www.dotnetbull.com/cross-domain-call.ashx?ref=jquery-jsonp-request&callback=jQuery1510993527567155793_137593181353

Response data should look like this :
jQuery1510993527567155793_137593181353( {  "result": "success", "ref": "jquery-jsonp-request" } )


string callback = context.Request.QueryString["callback"];

if (!string.IsNullOrEmpty(callback))
     context.Response.Write(string.Format("{0}({1});", callback, jc.Serialize(outputData)));
 else

     context.Response.Write(jc.Serialize(outputData));

jQuery ajax jsonp calls parse error after success

jQuery ajax jsonp calls parse error after success
jQuery ajax jsonp calls parse error after success

Popular Posts