简体   繁体   中英

Jquery callback not working inside done success function

On posting to server: i got jsonp({"code":"680","country":"UK","status":"Citizen"}); ie the content of result and am trying to access the value of country.

My attempt was creating my own jsonp function to access it.

done(function (result, status, xhr){

   console.log(result); 

    //log result is: 

    //jsonp({"code":"680","country":"UK","status":"Citizen"});
     transfer(result);
})

//outside of jquery call; i have this outside the click function.
function transfer(result){
   var xyz = result;
   function jsonp(xyz){
     alert(xyz.country);
   } 
 }

I don`t get to access the county in jquery done function.; In a nuetral script this works ie creating and html file for testing.

<script>
 var result = jsonp({"code":"680","country":"UK","status":"Citizen"});

  jsonp(result){
      alert(result.country);          // alert is UK
      console.log(result.country);   //result is UK.
  }
  </script>

Thank you.

You can do this.

    done(function (result, status, xhr){

       console.log(result); 

       //log result is: 

       //jsonp({"code":"680","country":"UK","status":"Citizen"});
       eval(result);
    })



    function jsonp(xyz){
      alert(xyz.country);
    } 

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