0

I have:

$.post( "https://host.com/save.php", { 'fb_id': userID, 'meth': 'get_db_ID' }, function(data) { link_id = data; console.log('from method' + link_id); }); FB.ui({ method: 'feed', name: 'My title for a link.', caption: ' ', description: 'My description', link: 'https://www.facebook.com/pages/Page-Test/1417010325197563?id=1417010325197563&sk=app_1413297985570561&app_data=u_id|'+link_id, picture: 'http://host.com/myimage.png' }, function(response) { console.log('publishStory response: ', response); }); 

But the var link_id I have defined previously and have assigned a user's id, doesn't display.

1 Answer 1

1

This is a problem caused by asynchronous events. The link_id is set in the callback function for the $.post. This callback function only runs once the POST request is complete - this could be a few seconds depending on the connection. But, the code after the $.post runs straight away - meaning the link_id is not set when you make the FB.ui call. Try this instead:

$.post( "https://host.com/save.php", { 'fb_id': userID, 'meth': 'get_db_ID' }, function(data) { link_id = data; console.log('from method' + link_id); FB.ui({ method: 'feed', name: 'My title for a link.', caption: ' ', description: 'My description', link: 'https://www.facebook.com/pages/Page-Test/1417010325197563?id=1417010325197563&sk=app_1413297985570561&app_data=u_id|'+link_id, picture: 'http://host.com/myimage.png' }, function(response) { console.log('publishStory response: ', response); }); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.