I am trying to use ajax
POST method to validate course number on my page. The helper.html
sends back correct value of i (true
or false
); that sets ValidCourse
to true when it is a valid course. But when I check the value of ValidCourse
after the ajax call; it always remains 'false
'. Why?
if (EnrollmentsCount == 0) { // validate course
var crsNum = "'" + $j("#course_number").val() + "'";
var ValidCourse = false;
// Ajax call to determine if course is valid course
$.ajax({
type: 'POST',
url: 'helper.html?crsNum=' + crsNum,
async: false,
success: function(i) {
if (i === 'true') {
ValidCourse = true;
}
}
});
if (!ValidCourse) { //it is always false whether it is a valid or invalid course
var errorMsg = "Please enter valid course number";
scroll('#course_number');
}
}