When I call ajax to retrieve a value from an asp page and return it to the calling javascript, the code looks like this:
function fetchNameFromSession() { xmlhttp = GetXmlHttpObject(); if (xmlhttp == null) { alert("Your browser does not support AJAX"); return; } var url = "getImageName.asp"; url = url + "?fetch_name=1"; xmlhttp.open("GET", url, true); xmlhttp.send(null); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { alert(xmlhttp.responseText); return xmlhttp.responseText; } } }
The alert inside the function displays the correct value. However, when I try to access the value in the calling javascript function, it returns undefined. Can anyone help me figure out how to properly return the value from this ajax call to the javascript function that called it?