jquery - pass the o/p of ajax to function -
this question has answer here:
- how return response asynchronous call? 21 answers
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
Post a Comment