Jump to content

Ajax Return Next Image Src


music_lp90
 Share

Recommended Posts

Hi, can someone explain why this happens:Here's the javascript section

	function checkForMoreImgs(id, last, limit){		//AJAX to check if there are more images in this category. if not, check if there is a row to go to		xmlHttp=GetXmlHttpObject();		if (xmlHttp==null)		  {		  alert ("Browser does not support HTTP Request");		  return;		  }		var url="http://www.###.com/administrator/gallery.class.php";		url=url+"?imgCat="+id;		url=url+"&lastPic="+last;		url=url+"&limit="+limit;		url=url+"&sid="+Math.random();		xmlHttp.onreadystatechange=checkForMore;		xmlHttp.open("GET",url,true);		xmlHttp.send(null);		}		function checkForMore(){ 		var paths;		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){			// If there are more images we want to replace them with new urls and get rid of any old ones that might be left			document.getElementById("0-0").src =xmlHttp.responseText; // !!!!!!!!!! THIS IS THE LINE IN QUESTION !!!		}	}	function GetXmlHttpObject(){	var xmlHttp=null;	try{	 // Firefox, Opera 8.0+, Safari	 xmlHttp=new XMLHttpRequest();	}	catch (e){	 // Internet Explorer		try{		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");		}		catch (e){		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");		}	}	return xmlHttp;	}

here's the php section

if(isset($_GET['imgCat'])){	$gallery = new gallery();	$category = $_GET['imgCat'];	$start = $_GET['lastPic'];	$limit = $_GET['limit'];	$gallery->getImagesByCategory($category, $start, $limit);	if($gallery->fullpath[0] != ''){		echo $gallery->fullpath[0] . $gallery->filename[0];	} else {		echo "<p>no more images</p>";	}} else {	echo "<p>Not Set</p>";}

In the javascript section, the line that says document.getElementById("0-0").src =xmlHttp.responseText in the checkForMore() function, if I do document.write(xmlHttp.responseText), I get the text that I want to insert into the src, but when I go document.getElementById("0-0").src =xmlHttp.responseText I get a whole long line of stuff.Below is what gets inserted in the src if it makes a difference, Thanks!http://www.###.com/%3Cscript%20type=%22tex...backgroundColor = '#999966';oldId = imgId + '-' + catNum;} function playShow(){setTimeout("next()", 500); // Slight delay for startt = setInterval("next()", 4000);} function stopShow(){clearInterval(t);} function next(){var splitOldId = oldId.split("-");var newId;var moreInRow = "no";if(splitOldId[0] == numImages[splitOldId[1]] - 1){newId = 0;var oldSrc = document.getElementById(splitOldId[0] + "-" + splitOldId[1]).src;checkForMoreImgs(categories[splitOldId[1]], splitOldId[0], perRow);newId = newId + '-' + splitOldId[1];splitOldId[0] = -1;} else {newId = parseInt(splitOldId[0]) + 1;newId = newId + '-' + splitOldId[1];//document.getElementById("code").innerHTML = "New ID: " + newId + " Old ID: " + oldId + " Split 1: " +splitOldId[1] + " Number of Images: " + numImages;}var alt = document.getElementById(newId).alt;var newSrc = document.getElementById(newId).src;var splitPoint = newSrc.lastIndexOf("\/");var start = newSrc.substring(0,splitPoint);var large = '/large/';var end = newSrc.substring(splitPoint + 1);newSrc = start + large + end;largeImg(newSrc, alt, parseInt(splitOldId[0]) + 1, parseInt(splitOldId[1]));}function checkForMoreImgs(id, last, limit){//AJAX to check if there are more images in this category. if not, check if there is a row to go toxmlHttp=GetXmlHttpObject();if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }var url="http://www.###.com/administrator/gallery.class.php";url=url+"?imgCat="+id;url=url+"&lastPic="+last;url=url+"&limit="+limit;url=url+"&sid="+Math.random();xmlHttp.onreadystatechange=checkForMore;xmlHttp.open("GET",url,true);xmlHttp.send(null);}function checkForMore(){ var paths;if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){// If there are more images we want to replace them with new urls and get rid of any old ones that might be leftdocument.getElementById("0-0").src =xmlHttp.responseText;}}function GetXmlHttpObject(){var xmlHttp=null;try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest();}catch (e){ // Internet Explorertry{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}return xmlHttp;} //--></script><div id="code"></div>http://www.###.com/images/current-projects/Pollard/Cellar-hole-before-frost-walls.jpg

Edited by music_lp90
Link to comment
Share on other sites

Everything on the end of the URL is Javascript. If you do document.write you're not going to see all of that written out, the browser doesn't render Javascript tags. If you used alert instead of document.write you'd see that the server is returning a significant amount of Javascript code with the response.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...