I am using the jquery webcam plugin with the flash save method. I want set a message after the user clicks save so they know it’s saving. My code is this:
$('#savepicmessage').html("Saving picture, please wait");
webcam.capture();
webcam.save('/savephoto.php');
The problem is that the “Saving picture” message only gets displayed after the picture is saved. Is there a way to prevent execution of the code following the .html(“Saving picture, please wait”) call, so that it is not executed until the message has been displayed?
I can achieve it with a setTimeout and have the capture and save in the function called from there, however this is not reliable enough.
I looked at .when and deferred.then but that didn’t seem to work.
In general I use promises and stuff like $.when() to coordinate asynchronous things like AJAX calls or animation. But the fact that this is acting almost like it’s asynchronous is amazing to me.
However, I have a suggestion. Can you loop on $(‘#savepicmessage’).html() after the first call to set it and test what comes back? Perhaps once the returned value matches what you tried to set it to, then you could fall through to the webcam functions and your message will be visible to the user prior to invoking the webcam.