Reputation: 2616
I am testing Parallel Jquery Ajax calls with
// $.When{}.done(fucntion(){// Something Here});
The Problem is whenthis page gets loaded and i press the button to invoke delegate() method, it does print Test1, Test2 and Test3 Not the Text which is being set through ajax calls. Can anyone spot an issue?
var response = [];
response.method1 = 'Test1';
response.method2 = 'Test2';
response.method3 = 'Test3';
function method1() {
$.ajax({
type: "GET",
url: '/Home/Method1',
dataType: "json",
success: function (data) {
response.method1 = data.Name;
},
error: function (jqXhr, textStatus, errorThrown) {
$("#error").html(jqXhr.responseText);
}
});
}
function method2() {
$.ajax({
type: "GET",
url: '/Home/Method2',
dataType: "json",
success: function (data) {
response.method2 = data.Name;
},
error: function (jqXhr, textStatus, errorThrown) {
$("#error").html(jqXhr.responseText);
}
});
}
function method3() {
$.ajax({
type: "GET",
url: '/Home/Method3',
dataType: "json",
success: function (data) {
response.method3 = data.Name;
},
error: function (jqXhr, textStatus, errorThrown) {
$("#error").html(jqXhr.responseText);
}
});
}
function deletegate() {
$.when(Progress(true),method1(), method2(), method3()).done(function () {
$("#response").append(response.method1 + '<br/>' + response.method2 + '<br/>' + response.method3 );
Progress(false);
} );
}
function Progress(show) {
if (show) {
$("#Prog").show();
} else {
$("#Prog").hide();
}
}
Upvotes: 0
Views: 49
Reputation: 1114
Because all your JS-functions return immediately without a return value, so .done is also called immediately and not waiting for async-call to end. guess: try return $.ajax(...) inside these functions
Upvotes: 1