jQuery ajax only works first time -


I have a table of data that click on the button, some values ​​are saved on the database, while other values Recover. I need a continuous process, but I can get it to work only for the first time.

At first I was using .ajax () and .replaceWith ()) to rewrite the whole table, but because it Overwrites the DOM, he was losing the events associated with the table. I can not use .live () because I am using stopPropagation () and .live () due to event bubble Does not support it. I was essentially able to force the click event on the table within the .ajax () callback, but there was nothing in the second call event to click on the button.

I changed the Ajax and .html () for the result of using the .get () in the code table (server-side The code now returns the complete table without & lt; table & gt; tag) I do not have to click the click event again in the table, but clicking on the button just does not do anything .

Finally, I changed it to .load () , but with the same (non-) result.

I mean, by "nothing", when the AJAX call is returning the expected new HTML, it is not being applied to the table. I am sure that this is something to change to DOM, but I thought that since I only overwrite table contents and do not write myself on the table, then it should work. Obviously I'm missing something; what is this?

Edit:

HTML:

  & lt; Table id = "table1" class = "mytable" & gt; & Lt; TR & gt; & Lt; Td> & Lt; Span id = "item1" class = "myitem" & gt; & Lt; / Span & gt; & Lt; / Td> & Lt; Td> & Lt; Span id = "item2" class = "myitem" & gt; & Lt; / Span & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; & Lt; Input id = "button1" type = "button" value = "submit" />  

jquery:

  $ ("button1"). Click (function () {$ ("table1"). Load ("data.aspx", function (data) {// ...});};  

Using the .replace method worked the first time, but. Use of Html method works only fine enough time JQuery:

  $ Data type: "html", success: function (data) {$ ('# divContainer'); Ajax ({type: "GET", url: '/ MyUrl / Id', data: "{}", cache: . Html (data);}})  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -