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>

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) {
}, ‘json’);*/

$.getJSON( urlFacebookCall+”?facebookAccountId=<?=$facebookAccountId?>&jsoncallback=?”,function(data) {

}//End of function callFacebookFile



//facebook_call.php into diff server.

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


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s


%d bloggers like this: