I have the below function erroring and its begin a real pain.
For some reason it is saing postData is not defined on the lines marked with error. But I have defined postData and populated it with the returned json from get.php?? Is there something missing here.
<script>
function postToFeed(shoeID) {
$.post("get.php",{id: shoeID},
function(data){
var postData = data;
}, "json");
var obj = {
method: 'feed',
link: 'https://developers.facebook.com/docs/reference/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
name: postData.title, //ERROR
caption: '<?=SHARE_CAPTION?>',
description: postData.description //ERROR
};
function callback(response){
if(response['post_id']){
$.post("vote.php",{id: '<?=(isset($_POST['fbid'])? $_POST['fbid'] : $data['id'])?>', shoe: shoeID, type: 'share'},
function(score){
$("#shoe_"+shoeID).html(score)
});
}
}
FB.ui(obj,callback);
}
</script>
Since you have defined it inside the success handler of post it is not accessible. Define
postDatain the outer scope it will work fine.One more thing to note here. You are using
$.postwhich makes anajaxcall asynchronously so even if you definepostDatain the outer scope it will not work because until the post request executes thepostDatais null or empty.So you should execute rest of the code inside the success handler of
$.post. Try this.