May 6, 201016 yr Sorry for double posting! Hi all, Ok so I have a piee of Ajax in my site thats baffling me. Im totally new to Ajax so any help will be much appreciated! 1) I have a form that passes a variable to the ajax function and works perfectly (as below). <form name='myForm'> <input type="hidden" id='id' name='id' value='<? echo $id; ?>' /> <input type='button' onclick='ajaxFunction()' value='Query MySQL' /> </form> 2) The function passes the variable to the desired page (includes/process_ajax_gallery_request.php) and works perfectly. 3) In the file (includes/process_ajax_gallery_request.php) i have a php function that querys the database and outputs some images. 4) Heres the prob: the output happens and is sent to "ajaxDiv" (as you will see below) but I cannot see anything on screen! I checked the source code of the HTML page and i can see that its there (ie <img src=.......>) but I cant see anything on the screen. I done a little research with no luck but is it something to do with the DOM or something? Totally new to this! Heres the Ajax function that takes care of it all: function ajaxFunction(){ var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your browser broke!"); return false; } } } ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxdiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var id = document.getElementById('id').value; var queryString = "?id=" + id; ajaxRequest.open("GET", "includes/process_ajax_gallery_request.php" + queryString, true); ajaxRequest.send(null); } Do I need to do something with this? ajaxDisplay.innerHTML = ajaxRequest.responseText; Any help is much appreciated. Thank you in advance and for reading this far! Wayne.
May 9, 201016 yr Hi! @waynef Instead of using innerHTML, try to create the element and add it as a child node within ajaxDisplay. Sometimes browser security can keep you from doing stuff, so try the same example by having the PHP script return a simple text string to make sure it works.
Create an account or sign in to comment