Reputation: 45
I have trouble with Ajax. It doesn't send variable "xxx" to file id.php. Code:
var xxx;
$.ajax({
url: "id.php",
success: function(result1) {
xxx = result1;
}
});
$.ajax({
url: "check.php",
data: "ids="+xxx,
type: "post",
success: function (result) {
.........
.........
}
});
Why it doesn't work?
Upvotes: 1
Views: 434
Reputation: 5443
It doesn't work because your second request is getting called before the first request completes.
you should have your second ajax request be wrapped in the success property of the first call.
success: function(result1){
$.ajax({
url: "check.php",
data: "ids="+result1,
type: "post",
success: function (result) {
.........
.........
}
});
}
Upvotes: 4