php - ajax call can't see what's wrong :S -


when click button load js file, nothing happens, have testet php file alone without ajax pure php , working! thinking there's wrong code here:

$(document).ready(function(){     $('#changepasswordneededbutton').click(function(){         $.post("http://example.com/change_password.php",         {             currentpassword : $('#currentpassword').val(),             newpassword : $('#newpassword').val(),             repeatnewpassword : $('#repeatnewpassword').val()         },             function(data){                 if (data.result == 1) {                     location.href = data.location;                 }             }, "json" // content has been returned in json format         );     }); }); 

the html this:

<div class='changepassword'> <div id='changepasswordinner'>     <form>         <input id='currentpassword' type='password' name='currentpassword' placeholder='nuværende adgangskode'>         <input id='newpassword' type='password' name='newpassword' placeholder='ny adgangskode'>         <input id='repeatnewpassword' type='password' name='repeatnewpassword' placeholder='gentag ny adgangskode'>         <input id='changepasswordneededbutton' type='button' name='changepasswordneededbutton' value='skift adgangskode'>     </form>     <div id'errorchangepassword'></div> </div> </div>  <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="../script/change_password.js"></script> 

and php:

if (isset($_post['currentpassword']) && isset($_post['newpassword']) && isset($_post['repeatnewpassword']) {      $currentpassword = $_post['currentpassword'];     $newpassword = $_post['newpassword'];     $repeatnewpassword = $_post['repeatnewpassword'];      $query = "select * user password = '$currentpassword'";     $result = $db->query($query);     while ($row = $result->fetch_assoc()) {         $password = $row['password'];     }      if ($password == $currentpassword) {         $update = "update user set password = '$newpassword' password = '$currentpassword'";         $db->query($update);         $result = array(             'result' => 1,             'location' => 'index.php',         );     }      // return result         echo json_encode($result);         die(); } 

i hope can see error here?

thanks..

take @ jquery's $.post documentation start. argue using $.ajax instead because of additional features it; ability add callbacks success , failure.

from jquery's docs on ajax:

   var jqxhr = $.ajax( "example.php" )   .done(function() {     alert( "success" );   })   .fail(function(jqxhr, textstatus, errorthrown) { // add error thrown console.logs here console.log(textstatus, errorthrown)      alert( "error" );   })   .always(function() {     alert( "complete" );   });  // perform other work here ...  // set completion function request above jqxhr.always(function() {   alert( "second complete" ); }); 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

qt - Passing a QObject to an Script function with QJSEngine? -

c# - Web API response xml language -