简体   繁体   中英

Get return value of dwr function within the located function

I want get the return value of dwr method within the located function.Ie, I have a javascript function name checkvalue().Within that I have a DWR call.I want the value returned by the DWR method.I have set the value to a hidden variable.But it cannot get properly.How can I do that?Please help me.

Thank you

<script type="text/javascript">
   function checkvalue(applNo){
     classDAO.getstatusofApplication(applNo,getstatusofApp); 
     var status=document.getElementById("hiddenfield").value;
   }

   function getstatusofApp(status){  
     document.getElementById("hiddenfield").value=status;   
    }
</script>

In the above example I set the dwr return value 'status' to a hidden field and call the hidden field within the checkvalue method.But it shows null.

I think in your code the line

var status=document.getElementById("hiddenfield").value;

gets executed before the function getstatusofApp is being called. try logging in console the steps the code is executed.

So what you really should do is-

function checkvalue(applNo){
   classDAO.getstatusofApplication(applNo, function(status){
      getstatusofApp(status);
      alert(status);
      // here you have the status value you need not have 
      // to read it from hidden variable
   }); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM