Posted by: prajapatinilesh | May 14, 2012

jquery cross domain ajax request using JSON

// Include jquery library. <script src=”jquery file path”>

<div id=”facebook_feed_display_div” style=”height:300px;width:420px;overflow:auto;”></div>

<script>
function callFacebookFile() {
$(“#facebook_feed_display_div”).html(‘<span style=”color:red;font-size:13pt”>Loading Please Wait….!</span>’);

var urlFacebookCall = ‘http://different_server_url/facebook_call.php&#8217;;

var parameterString = ‘facebookAccountId=<?=$facebookAccountId?>’;
parameterString += ‘&param2=<?=$param2?>’;

/*var url = urlFacebookCall+”?facebookAccountId=<?=$facebookAccountId?>&&jsoncallback=?”;
$.get(url, function (data) {
$(“#facebook_feed_display_div”).html(data.msg);
}, ‘json’);*/

$.getJSON( urlFacebookCall+”?facebookAccountId=<?=$facebookAccountId?>&jsoncallback=?”,function(data) {
$(“#facebook_feed_display_div”).html(data.msg);
});

}//End of function callFacebookFile

callFacebookFile();
</script>

//———————————————————————————

//facebook_call.php into diff server.

$array = array(“msg”=>”hello”); //some bogus data
echo $_REQUEST[‘jsoncallback’].”(“.json_encode($array).”)”;
return;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: