submit()函数有回调吗? [英] Does submit() function has a callback?
问题描述
setMyCookie('name', 'value_1');
$('。myform')。submit();
setMyCookie('name','value_2');问题:Webkit浏览器似乎在表单被提交之前用value_2更新MyCookie,或者,在确切的时刻,它被提交,所以错误的cookie值与它一起发送。
我想在表单提交后立即将cookie值更改为'value_2',以便cookie可以用于另一个请求。
以下代码可以正常工作,但我不认为使用timeout()是最好的解决方案。也许有另一种方法来解决这个问题?
setMyCookie('name','value_1');
$('。myform')。submit();
setTimeout(function(){setMyCookie('name',value_2);},100);
谢谢。
解决方案否。提交表单会加载一个全新的页面,通常会结束脚本的当前执行上下文。
例外情况是如果您将表单提交到框架,在这种情况下一个onload事件将触发。
I have this code, and a file upload form which is submited to a frame:
setMyCookie('name','value_1');
$('.myform').submit();
setMyCookie('name','value_2');
Problem: Webkit browsers seem to update 'MyCookie' with 'value_2' before the form gets submited, or in the exact moment it is being submited, so wrong cookie value is sent with it.
I want to change cookie value to 'value_2' immediately after the form is submited so the cookie is ready for another request.
The following code works fine, but I don't think using timeout() is the best solution. Maybe there is another way to solve this problem?
setMyCookie('name','value_1');
$('.myform').submit();
setTimeout(function(){setMyCookie('name',value_2);},100);
Thanks.
解决方案 No. Submitting a form loads an entirely new page, which usually ends the current execution context for the script.
The exception is if you submit the form to a frame, in which case an onload event will fire.
这篇关于submit()函数有回调吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!