jquery - Alert() does not fire from the second page of datatable -


i have datatable returned backend using jquery , datatables plugin. need select order number in datatable , alert it. alert , console works in first page of data table not fire anymore second page. googled .live() deprecated , suggested answer .on()seems not work.

jquery:

$(document).ready(function () { $.ajax({     type: "post",     //url: "orderdetail.asmx/helloworld",     url: "order.aspx/getorder",     data: "{'id':'273440'}",     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function (msg) {         $('#order').append(msg.d);         //alert(msg.d);         console.log(msg);         $('#ordertable').datatable({             // "sscrolly": "100px",              "bautowidth": false,             "bdeferrender": true             //"bpaginate": false          });         // click order number details         // problem here          $('.ordernumber').on('click', function () {             var ordernum = $(this).text();             console.log(ordernum);         });      },     error: function (xhr, status, error) {         // display generic error now.         alert("ajax error!");     } }); 

});

the onclick event set applies elements on page. why works first page. should set onclick events whenever datatables shows new results. can accomplished moving onclick listener datatables' fndrawcallback function.

$('#ordertable').datatable({     // "sscrolly": "100px",      "bautowidth": false,     "bdeferrender": true,     //"bpaginate": false,      "fndrawcallback": function() {         $('.ordernumber').on('click', function () {             var ordernum = $(this).text();             console.log(ordernum);         });     } }); 

see http://datatables.net/ref#fndrawcallback


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -