jquery html replace page with $(document).ready code -


i using jquery replace html in site. html getting inserted has "$(document).ready" function @ bottom of page. code not getting run when html gets replaced. guess makes sense because whole page not loading. replacing html. best way make sure code runs? here code doing replacing:

function procview(url, e) {     var data = $('.checkout form').serialize();     $.ajax({         url: '/shop/' + url,         data: data,         success: function (result) {             $('.rightpane').html(result);             $('#dvsummary').load('/shop/_summary');             validatecc();         },         error: function (result) {             alert(result.responsetext);         }     }); } 

it .html(result) line. if matters, using asp.net mvc5.

and here document.ready code validatecc() function:

$(document).ready(function () {             alert("out of function!");             //$.validator.setdefaults({ ignore: ":hidden, .data-val-ignore" });             function validatecc() {                 alert("in function!");                 $('#cardnum').validatecreditcard(function (result) {                     $("#cardnum").attr('class', 'data-val-ignore');                     if (result.card_type != null) {                         $("#cardnum").addclass(result.card_type.name);                     }                     if (result.card_type != null && $("#cardnum").val().length == result.card_type.valid_length) {                         $("#cardnum").addclass("valid");                     }                 },                 { accept: ['visa', 'mastercard', 'amex', 'discover'] });             }         }); 

neither of alerts run me. in fact get: "referenceerror: validatecc not defined".

with ajax function know when correctly executed, therefore, once have loaded content using .html() function call function want executed.

let's have on second document:

<div class="test">hello</div> <script>     function dosomething() {         $(document).find(".test").text("hello world");     } </script> 

in success function this:

success: function (result) {     $('.rightpane').html(result);     $('#dvsummary').load('/shop/_summary');     dosomething(); } 

to honest not sure 100% work can try.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -