JQuery `live ()` and `submit ()` problem

I want to do something similar, but this one looks happing for endless 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 submits, something like 10 seconds and in IE crashes!

I know when I say form.submit means that I represent it and get the called function again and again, how can I avoid this?

+3
source share
1 answer

By fring .submit()again, which returns to .live(), you call an infinite loop, instead you want to call the native method form.submit(), for example

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

.action DOM, ... jQuery .

+11

Source: https://habr.com/ru/post/1778954/


All Articles