I am trying to use $.when to execute my Ajax Request and to do manipulate data after their execution. Here is my code until now:
function method2 (data2) {
return $.ajax({
type: 'GET',
url: 'Some URL',
dataType: 'jsonp',
success: function(data2){
console.log(data2);
}
});
}
function method3 (){
return $.ajax({
type: 'GET',
url: 'Some URL',
dataType: 'jsonp',
success: function(data3){
console.log(data3);
}
});
}
function method4(){
return $.ajax({
type: 'GET',
url: 'Some URL',
dataType: 'jsonp',
success: function(data4){
console.log(data4);
}
});
}
function method5(){
return $.ajax({
type: 'GET',
url: 'Some URL',
dataType: 'jsonp',
success: function(data5){
console.log(data5);
}
});
}
function method6(){
return $.ajax({
type: 'GET',
url: 'Some URL',
dataType: 'jsonp',
success: function(data6){
console.log(data6);
}
});
}
// Execute all needed data from all of the requests.
function showData(){
}
$.when( method1(), method2(), method3(), method4(), method5(), method6() ).then( showData() );
So I would like to show the data from these Ajax get requests on my HTML page and I would like to execute all of the code inside function showData() but the problem is that I do not have access to my methods when I try to console.log() them inside showData() and I would like to know how I can access them ? Any solution or ideas ?
$.when()