jquery - pass the o/p of ajax to function -


this question has answer here:

var left=$('.left p');     left.click(function(){        var index= $(this).index('.left p');                var returned_data= ajaxcall(click_name);       console.log(returned_data)                     });      function ajaxcall(name)    {        $.ajax({                 type: "post",                                     url: "retrivedata.php",                                      data:{click: name},                        cache: false,                                           success: function(data)                  {                     var p=data;                                             return p;                                     }          })    } 

i need value in variable p passed click function variable returned_data. returned_data showing undefined. can please tell me wrong code here

you can't return data ajax that. ajax asynchronous. function not wait success event happen.

you can call function success event data. best possible approach.

$.ajax({     type: "post",     url: "retrivedata.php",     data: {         click: name     },     cache: false,     success: function(data) {         var p = data;         manipulatedata(p);     }  });  function manipulatedata(data) {     console.log(data); } 

Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -