0

I would like teacherID to be returned from this function so I defined the variable outside the function the actual value is created but it doesn't seem to be working any help? (P.S. Was not sure what this sort of variable is called )

function getTeacherID(courseID,block,roomID){
    //Get the rooms for the subjects the student does
    var teacherID;
    function doXHRPromise() {
        return new Promise(function(resolve, reject) {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    resolve(this.responseText);
                }
            }
            var everythingArray = [courseID,block,roomID];
            xmlhttp.open("GET", "getTeacherIDTimetable.php?q=" + JSON.stringify(everythingArray), true);
            xmlhttp.send(); 
        });
    }
    doXHRPromise().then(function(responseText) {
        teacherID = responseText;
    });
    return teacherID;
}
Dilly
  • 39
  • 4

0 Answers0