Monday 15 March 2010

Wait till for completes using jQuery / Javascript -



Wait till for completes using jQuery / Javascript -

how can create code wait till form gets response. form must submit recurly , receive response recurly before can go on.

if there way assure there response nice kinda success: or error:

$("#pay_window").dialog({ autoopen: false, width: 600, buttons: { "submit payment": function(){ $("#paymentform").submit(); <--- need wait function here ---> var dialogbox = $(this); $.ajax({ url: "/payment", data: $(this).find([company_id, billing_email, first_name, last_name, recurly_token, selected_plan, account]).serialize(), type: "post", success: function (data) { dialogbox.dialog("close"); alert('payment completed') }, error: function (jqxhr, textstatus, errorthrown) { alert('error: ' + textstatus + ': ' + errorthrown); } }); homecoming false; } } });

a form submit essentially same thing post endpoint specified form's "action" attribute (or page containing form). gather form info , create post (via jquery recurly) , utilize jquery's deferred object methods ('then', 'done', 'fail', etc.) or utilize $.ajax , success/error options...granted won't work in ie 7/8/9 (there's no access formdata object).

given rather on simplistic form:

<form id="foo" action="http://example.com/" method="post"> <input type="hidden" name="q" value="a"> </form>

one grab input , create 'formdata' object:

var $foo = $('#foo'), formdata = new formdata($foo[0]), $.ajax({ url: $foo.attr('action'), data: formdata, type: "post", success: function (data) { /* want */}, error: function (jqxhr, textstatus, errorthrown) { /* you've got */ } });

javascript jquery

No comments:

Post a Comment