I am a newb with JSONP so I am hoping someone will help me from the ground up.
Basically my situation is:
I have a server with a CMS. I want information from the CMS to appear on several other sites.
So I am thinking (but am unsure) that I put the information I want to transmit in a PHP variable. I then use
echo json_encode($json);
then on the sites I wish to display the information on I use JQuery to:
$.ajax({
url: 'http://www.mycmssite.com/phppage.php?json',
dataType: 'json',
data: json,
success: callback
});
var myvar = success;
document.write(myvar);
Now this is my preliminary understanding and I know its full of holes. But if someone could point me in the right direction that would be awesome!
Thanks heaps!
Make sure your Ajax requests specifies
dataType: 'jsonp'instead. This will allow the call to get around the same-origin policy and add a jQuery generated callback function name.Make sure your server script can detect the fact that a callback function name was passed and that it wraps the response within that function.
For example, when your service is called with a callback:
your response will be something like:
Also, the success property should be set to an existing function that will execute some logic on the JSON data it receives.