Precautions for using jquery live

  • 2020-03-30 01:48:59
  • OfStack

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - by far

Recently, development encountered a strange problem, when a button was clicked to submit, many requests occurred, resulting in data duplication.

So, after debugging, the cause of the problem is $("#id").live("click", function() {}); In this live case, using bind might not do the job, because if the asynchronous request returns HTML instead of json, the bind component may become invalid when the page is refreshed using HTML.

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

So you end up with an onclick attribute on top of an HTML tag element.

This solves both the asynchronous return HTML format and the one-click, multiple-request bug caused by multiple bindings similar to the multiple HTML () page refreshes (including the js section).

Related articles: