views:

677

answers:

2

I have an application which will post a message on a friends wall using the Facebook.streamPublish() method, and this works perfectly. However, I want to also be able to save details about this post in my database.

All the information that needs to be stored is placed into hidden form fields and are all in place once the message has been sent, so I figure that all I need to do is redirect to a php file which will take this information, save it into the database and then redirect back to the main page.

The streamPublish call is:

Facebook.streamPublish(\'\', attachment, null, params.ids[curFriend]);

which I can follow with form.submit() which will cause the redirect to happen, but this submit() function gets called instantly, and doesn't wait for the streamPublish() popup to load, be used, and the action to be completed. How can I make my form.submit() not be called until the user has hit the 'publish' button in the popup which occurs?

+1  A: 

I've not used the streampublish() function or the FB API, but I can guarantee that this is because the streampublish is handled by an ajax call, which is thus handled separately from the normal JS code chronology. So any code that should be executed when the ajax has reached a specific state needs to be added to the ajax statehandler, which the FB API may or may not give you access to.

Sandman
Yes, you are correct. streamPublish() loads a ajax popupbox thing, so the submit() beneath is called straight after while the popup does its thing separately. I was thinking I might be able to make the JS wait for streamPublish() to complete by making it check for something that streamPublish() changes when it is completed... But I don't really know what is going on so I can't.
lukeo05
+1  A: 

StreamPublish also takes an optional callback function - http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.streamPublish . Try setting your submit() function as the callback and it should get called once the user cancels the dialog or publishes it

Sabazou