jquery - Sending JSONP from PHP site to multiple sites -
i newb jsonp hoping me ground up.
basically situation is:
i have server cms. want information cms appear on several other sites.
so thinking (but unsure) put information want transmit in php variable. use
echo json_encode($json); then on sites wish display information on 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 preliminary understanding , know full of holes. if point me in right direction awesome!
thanks heaps!
make sure ajax requests specifies datatype: 'jsonp' instead. allow call around same-origin policy , add jquery generated callback function name.
make sure server script can detect fact callback function name passed , wraps response within function.
for example, when service called callback:
http://www.mycmssite.com/phppage.php?json=1&callback= jquery17109598642324563116 your response like:
jquery17109598642324563116({json response here}) also, success property should set existing function execute logic on json data receives.
- read documentation $.ajax details on other properties, data, sure understand what's expected here.
Comments
Post a Comment