I am using ajax call’s to perform POST and GET operations from a WebService hosted on some server.
I am using dataType:”jsonp” due to the cross domain issue.I can see the data being sent by the web service on fiddler. I want to access the data which I get from the service and I dont know how do do that.
This is my ajax call:
$.ajax({
type: method,
url: "url",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
jsonp: false,
jsonpcallback:function(data){}, //What am I supposed to write here so that I can get the JSON data from Padded json
success: successHandler,
error: errorHandler
});
This is the approximation of the json response that I receive from the service:
{"Ideas":[
{"Message":null,"IdeaId":1},
{"Message":null,"IdeaId":1}
]
}
Any kind of help will be greatly appreciated. I searched through a lot of posts but could not get through.
Thank you in advance.
Usually, nothing. You only need to specify the callback if your JSONP service is really atypical. If you do specify it, it needs to be a string.
Likewise you shouldn’t set
jsonp: falseas that will prevent the callback parameter being generated.You do need a success handler to handle the data though. Having an error handler is also a good idea.
Then the JSONP handler needs to actually return JSONP
The
Content-Typeheader returned by the server should beapplication/javascriptThe body should be:
callbackkey in the query string();e.g.