javascript - empty input value after ajax call -


i have ajax call make after button click in html code:

html:

<div id="singlemethod">     <input type="hidden" id="teachersol" value="">     [...]     <button type="button" id="run" onclick="javascript:play(1, 105, 2)">      <img src="./images/green_play.png" width="40px" height="40px"> </button> </div> 

javascript/ajax:

function play(mn, id, nofm) {      (i=1; i<=nofm; i++)          getsolution (i, id, mn);      executemethod (mn, id); }  function getsolution (mn, id, actmn) {      $.ajax({              type: "get",              url: "ajax/getteachsol.php",              data: "id="+id+"&number="+mn,              success: function(data){                       $('#teachersol').val(data);              }      });      return false; }  function executemethod (mn, id) {      var teach= document.getelementbyid('teachersol').value;      alert (teach);      [...] } 

if check value alert prints nothing, if inspect element chrome see expect in value field. idea of why it's not printing in executemethod? may problem ajax (i'm pretty new @ it)? if need additional information ask! thank you!

function getsolution (mn, id, actmn) {      $.ajax({              type: "get",              url: "ajax/getteachsol.php",              data: "id="+id+"&number="+mn,              success: function(data){                       $('#teachersol').val(data);  executemethod (mn, id);              }      });      return false; } 

please change code little bit can call executemethod inside ajax function

  function play(mn, id, nofm) {          (i=1; i<=nofm; i++)              getsolution (i, id, mn); //and remove here     } 

now check getting same result? have not tested although

reason because alert calling before ajax gets completed


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -