Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  36] [ 5]  / answers: 1 / hits: 16710  / 14 Years ago, tue, december 7, 2010, 12:00:00

I wanna do something like this, but this one looks like happing for infinite times.



$(form).live(submit, function() { 

if($(this).attr('action') != ajax){
$(this).submit();
return true; // even i do this!! but form is NOT submited!!
}

else { /* doing the ajax stuff! */ }
});


in Chrome and Firefox after a while the form gets submitted, something like 10seconds and in IE it crashes !



I know when i say form.submit means that i am submitting this and get called function again and again, how can i avoid this ?


More From » jquery

 Answers
8

By fring .submit() again, which bubbles back to the .live() handler, you're causing an infinite loop, instead you want to call the native form.submit() method here, like this:



$(form).live(submit, function() { 
if(this.action != ajax) {
this.submit();
}
else { /* doing the ajax stuff! */ }
});


Also .action is a native DOM property, you can access it that way...not need for the jQuery overhead here.


[#94696] Sunday, December 5, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
beatrizrheaq

Total Points: 73
Total Questions: 89
Total Answers: 107

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
;