$.ajax({
method: "POST",
//dataType: "json", //type of data
crossDomain: true, //localhost purposes
url: "./query/singlecourse.php", //Relative or absolute path to file.php file
data: {id: i}, //passo i come parametro
success: function(response) {
var course=JSON.parse(response);
var el1="";
console.log(JSON.parse(response).length+" contenuti");
el1="<br><p style='font-size:53px;line-height: 0.5;font-family: Gloria Hallelujah;'>"+course[0].title+"</p><br><br><div class='contenitoreSpeciale'><style> .contenitoreSpeciale {border-radius: 25px; background-color: #d7dcfa;border: 4px solid #6e98f7; padding: 20px; width: 90%; margin-left:5%; height: auto}</style><img src='http://hyp.altervista.org/images/courses/"+course[0].image+"'><br><br><br><p style='font-size:18px;line-height: 1;'>"+course[0].description+"</p></div>";
$instructorID=course[0].instructor;
console.log($instructorID);
$(".contenitore-dinamico").html(el1);
},
error: function(request,error)
{
console.log("Error");
}
});
console.log($instructorID);
$.ajax({
method: "POST",
//dataType: "json", //type of data
crossDomain: true, //localhost purposes
url: "./query/singlecourse.php", //Relative or absolute path to file.php file
data: {id: instructorID}, //passo instructor come parametro
success: function(response) {
var instructor=JSON.parse(response);
var el1="";
el1="<br><br><br><div class='contenitoreSpeciale'><style> .contenitoreSpeciale { background-color: #baa8ba;border: 2px solid #534053; padding: 20px; width: 90%; margin-left:5%; height: auto}</style><p style='font-size:53px;line-height: 0.5;font-family: Gloria Hallelujah;'>Teacher of the course: "+instructor[0].name+" "+instructor[0].surname+"<img align='right' src='"+instructor[0].th_image+"'>";
$(".contenitore-dinamico").append(el1);
console.log($instructorID);
},
error: function(request,error)
{
console.log("Error");
}
});
}
My problem is that "Uncaught ReferenceError: $instructorID is not defined" cause the first ajax call works after the console.log. How can i stop for a while the rest of the code after ajax call? WIthout setTimeout if it's possible... i tried it but it was confusing. I want that only after the first ajax call the second starts. Thank you!