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

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -