php Codeigniter and jquery ajax -
i want call codeigniter controller ajax after login. when execute it, login page refreshed , ajax url isn't calling controller function of codeigniter.
i don't understand happened. please help?
below code
function validatereg() { var username = document.getelementbyid("inputname").value; var password = document.getelementbyid("inputpassword").value; $.post("<?php echo site_url('panel/login') ?>", {checkuser: username, checkpassword: password, action: "validateuser"}, function (data) { var result = data + ""; if (result.lastindexof("success" > -1)) { $.ajax({ url: "<?php echo site_url('dashboard/state'); ?>", type: 'post', complete: function (done) { console.log("finished.") } }); } }); }
here panel , dashboard 2 different controllers
it gets refreshed because it's submit button , must inside form. submits form on click event.
what need make function return false
on click of button page doesn't refreshed.
update html this,
<button type="submit" class="btn button text-uppercase" onclick="return validatereg();">login </button>
and js function this:
function validatereg() { var username = document.getelementbyid("inputname").value; var password = document.getelementbyid("inputpassword").value; $.post("<?php echo site_url('panel/login') ?>", {checkuser: username, checkpassword: password, action: "validateuser"}, function (data) { var result = data + ""; if (result.lastindexof("success" > -1)) { $.ajax({ url: "<?php echo site_url('dashboard/state'); ?>", type: 'post', complete: function (done) { console.log("finished.") } }); } }); return false; }
Comments
Post a Comment