Jump to content

Recommended Posts

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;



 }

} 

Link to comment
https://forums.phpfreaks.com/topic/183371-need-ajax-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/183371-need-ajax-help/#findComment-968148
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.