开发者

Can't detect when post requests finish

I am submitting multiple data multiple times on one button click.

First I submit data to a variable number of hidden iframes (the form is enctype="multipart/form-data"). Then I would like to run the normal submit button/function which redirects the main page.

开发者_StackOverflow社区If i do this all in one function though, I don't end up recieving all the data I send to the hidden iframes. I believe the redirect begins before the other forms finish sending (sometimes I receive the first data submitted, most of the time I receive none).

I have hacked a solution using setTimeout(function(){$("#submitbtn").click()},3000)... but clearly this won't always take 3 seconds. I want a way of detecting when it finishes so I can start the submit.

Sorry if this is hard to understand, if you need more info just comment/ask.


I'm not sure how you are submitting that data to the iframes but if you are using $.ajax you can set async : false which will pause every jQuery event, animation, etc. There may be something similiar if you are using a different method.


If you are using AJAX I recommend using the success callback of jQuery's $.post.

e.g.

$.post('/process', form_data, function(data) { document.location = '/thankyou'; false})

In this example after the post data has been successfully submitted the user will be redirected to /thankyhou

You can also use $("#submitbtn").click() in the callback.


I managed to do it by using the IFRAME.load, to detect changes to the target iframes. Once all iframes.load()'s fired I fired the last submit (the one that redirects the main page).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜