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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -