Can someone help me understand JSONP a little better?
I have a json file being out putted to a url. But due to same-origin policy I need to use JSONP. My question is do I need to change the actual JSON file or will using an ajax call with jquery, dataType: ‘jsonp’ do the work for me?
JSONP is nothing but, JSON with padding i.e. JSON wrapped by a function call. This format helps to pass the JSON data to java script.
JSON came into picture, when the JSON i.e. java script object can be used to represent the data, which was previously represented in the form of XML.
For example,
var data={...};is data in json format. Whereas In JSONP, same data is written asgetData(data);In your scenario of ajax call,
dataType:'jsonp', json data has to be passed as an argument to a function. You can access the response in that function.If you could have provided some code, it will be easy to resolve your query. Information about JSONP is available on wikipedia here.