I want to know how to pass value from ajax function to another ajax I’ve tried this code but It does not work. Anyone know how to do it the right way? Thanks!
$("#button").click(function(){
var passedValue = '';
$.ajax({
url://
type://
success:function(data){
if(typeof==="object"){
for(var i=0;i<data.length;i++){
passedValue = data[i]["passedThis"];
}
}
}
});
$.ajax({
data: { receivedPassed: passedValue;}
});
});
Those requests are asynchronous, so
passedValueisn’t ready by the time the second one is sent. You’ll probably want to send them in order:Also, you’re overwriting
passedValueeach time through that loop. Did you mean+=instead of=, or to use an array, or something?