buckibooster Posted March 8, 2015 Share Posted March 8, 2015 (edited) function getXMLHttp(){ var xmlHttp; try { //Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch(e) { //Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert("Your browser does not support AJAX!") return false; } } } return xmlHttp;}function populateEntries(menu, userName, entryRow){ var xmlHttp = getXMLHttp(); xmlHttp.onreadystatechange = function() { if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200) && (xmlHttp.responseText == "")) { window.alert("There are no records to view!"); } else if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) { var response = xmlHttp.responseText;// window.alert("PHP Response = '"+response+"'"); } } xmlHttp.open("GET", "getUsers.php", true); xmlHttp.send(null);// ADDITIONAL UNRELATED CODE THAT PARSES THE “RESPONSE,” CREATING A MULTIDIMIENSIONAL ARRAY, WHICH POPULATES A SELECT INPUT FOLLOWS ....} I am using an AJAX call from a javascript to populate a SELECT input. This script is not working as shown in the code excerpt below. However, when I insert an alert of any type at the location shown by the comment, it works as planned. What could be causing this? I've also tried, without success, inserting a delay function after the AJAX call to allow time for the response to be returned (even with the readystate and status tests shown). Any suggestions as to how I can get this to work as desired? Edited March 8, 2015 by buckibooster Link to comment Share on other sites More sharing options...
davej Posted March 8, 2015 Share Posted March 8, 2015 I am using an AJAX call from a javascript to populate a SELECT input. Where is that code? Link to comment Share on other sites More sharing options...
buckibooster Posted March 8, 2015 Author Share Posted March 8, 2015 Moderator: That part of the code is working and unrelated to the AJAX call problem. I choose to protect that code with the "additional unrelated code that ..." statement at the end of my code snippet. Link to comment Share on other sites More sharing options...
Ingolme Posted March 8, 2015 Share Posted March 8, 2015 You have to deal with the response inside the onreadystatechange event handler. The variable response is local to that function and is not accessible from outside. Link to comment Share on other sites More sharing options...
davej Posted March 8, 2015 Share Posted March 8, 2015 If you see the response text appear in the alert then this code is working also, so I don't see how you can conclude that the other code is "unrelated." Link to comment Share on other sites More sharing options...
buckibooster Posted March 8, 2015 Author Share Posted March 8, 2015 Thanks Ingolme! That not only solved the problem I was having but another related problem that I didn't even know I had. Thanks again! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now