sheena_bandy Posted November 30, 2009 Share Posted November 30, 2009 I'm having a hard time getting this to display the data in the gallerydiv or at all on the page. I'm still new to AJAX, so I've been working on this for nearly 5 hours and can't figure out what's wrong with it. Any help would be greatly appreciated. function GetXmlHttpObject() { var objXMLHttp=null; if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); } return objXMLHttp; } var xmlHttp; function showInfo(str){ // set up xmlHttpRequest object xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert ("Browser does not support HTTP Request"); return; } // prepare to send the xmlHttpRequest object var url="galleryback.php"; url=url+"?YID="+str; // catch the readystatechange event and bind it to the processing function xmlHttp.onreadystatechange=function(){stateChanged(str)}; // send the request xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged(str) { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { // get the request result as an XML document xmlDoc=xmlHttp.responseXML; // set the variable to store HTML output var output = ""; // store all elements in an array var imageArray = xmlDoc.getElementsByTagName('IMG'); // loop through all elements in the XML document for (i=0;i<xmlDoc.getElementsByTagName('IMG').length; i++) { output = output + "<div style='float: left;'><a href='javascript: imgpopup("+xmlDoc.getElementsByTagName('IID')[i].childNodes[0].nodeValue+","+xmlDoc.getElementsByTagName('extension')[i].childNodes[0].nodeValue;+");'<img src='images/gallery/" +xmlDoc.getElementsByTagName('IID')[i].childNodes[0].nodeValue; output = output + "_small." + xmlDoc.getElementsByTagName('extension')[i].childNodes[0].nodeValue; output = output + "' /></div>"; } output = output + "<br style='clear: both;' />"; // print out the HTML output in the specified div document.getElementById('gallerydiv').innerHTML= output; } } Quote Link to comment https://forums.phpfreaks.com/topic/183371-need-ajax-help/ Share on other sites More sharing options...
abazoskib Posted November 30, 2009 Share Posted November 30, 2009 any errors? check the error console in firefox, or firebug Quote Link to comment https://forums.phpfreaks.com/topic/183371-need-ajax-help/#findComment-967995 Share on other sites More sharing options...
sheena_bandy Posted November 30, 2009 Author Share Posted November 30, 2009 no errors. It just doesn't parse the xml. Quote Link to comment https://forums.phpfreaks.com/topic/183371-need-ajax-help/#findComment-968105 Share on other sites More sharing options...
abazoskib Posted November 30, 2009 Share Posted November 30, 2009 lets check to see if you are even getting any return.. //REPLACE THIS: // get the request result as an XML document xmlDoc=xmlHttp.responseXML; //WITH THIS: // get the request result as an XML document xmlDoc=xmlHttp.responseXML; alert(xmlDoc); Then test out your page, and let me know if you get any type of return. Quote Link to comment https://forums.phpfreaks.com/topic/183371-need-ajax-help/#findComment-968148 Share on other sites More sharing options...
sheena_bandy Posted November 30, 2009 Author Share Posted November 30, 2009 the alert says this [object XMLDocument] Quote Link to comment https://forums.phpfreaks.com/topic/183371-need-ajax-help/#findComment-968204 Share on other sites More sharing options...
sheena_bandy Posted November 30, 2009 Author Share Posted November 30, 2009 It's solved! Someone spotted a syntax error that I hadn't seen and now the thing works. Thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/183371-need-ajax-help/#findComment-968268 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.