maxudaskin Posted August 16, 2010 Share Posted August 16, 2010 Hi Guys! I'm working on a website feature that will grab information about a selected airport from a MySQL database. The information will be grabbed and displayed, assuming that the airport identification is correct, to the screen, although I am having some troubles here. The code is below. Excerpt from front end <div class="contentBox cb_blue mar_bottom"> <input type="text" name="departure" id="departure" style="width:350px;" onChange="loadAirportInfo('departureInfo', 'this.value')" value="<?= @$_POST['departure']; ?>"> <div id="departureInfo"></div> </div> loadAirportInfo code function loadAirportInfo(elemId, ident) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById(elemId).innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","include/lib/ajaxAddInfo.php?get=airportInfo&airport="+ident,true); xmlhttp.send(); } ajaxAddInfo.php code <?php if($_GET['get'] == 'airportInfo') { $sql = 'SELECT * FROM `geo_airports` WHERE `ident` = \'' . $_GET['ident'] . '\''; $query = mysql_query($sql); if(mysql_num_rows($query) < 1) { return ''; } else { $result = mysql_fetch_array($query); return 'Identification: ' . $result['ident'] . '<br />' . 'Airport Name: ' . $result['name'] . '<br />' . 'Municipality: ' . $result['municipality'] . '<br />' . 'Country: ' . $result['country'] . '<br />'; } } ?> Now, I am sure that the issue is with the AJAX and not the PHP or regular Javascript. Thank you for your help and opinions in advance. Max Link to comment https://forums.phpfreaks.com/topic/210897-php-ajax-mysql-information-bar-the-issue-is-with-ajax/ Share on other sites More sharing options...
maxudaskin Posted August 16, 2010 Author Share Posted August 16, 2010 Here is a cap of a few rows of the database, even though, it won't help much. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/210897-php-ajax-mysql-information-bar-the-issue-is-with-ajax/#findComment-1099994 Share on other sites More sharing options...
maxudaskin Posted August 16, 2010 Author Share Posted August 16, 2010 The issue was, I was returning the value, not echoing it. Link to comment https://forums.phpfreaks.com/topic/210897-php-ajax-mysql-information-bar-the-issue-is-with-ajax/#findComment-1099997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.