Jump to content

Mismatched Tag: Expected </img>


hybrid kill3r

Recommended Posts

I have an ajax code that displays the certain month of a calendar. There are buttons before and after the month name to switch to the next and previous months. The only error I am getting in Firebug error console is a message saying: "mismatched tag: expected </img>". which doesn't make sense to me since you don't use a </img> tag when using images. I even tried adding that tag after the normal img tag, but not even that fixed it. Also, the calendar doesn't display, only "[object HTMLCollection]"... but that's probably because of the JS error. Here's my code:

// JavaScript Document var xmlhttp=GetXmlHttpObject();if (xmlhttp==null)  {  alert ("Your browser does not support AJAX!");  }var url="ajax.php";url=url+"?what=month";xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);function switchMonth(switchTo, switchFrom){		var ajaxURL = "ajax.php";	var URLExtension = "?what=month&with="+switchTo;		xmlhttp=GetXmlHttpObject();if (xmlhttp==null)  {  alert ("Your browser does not support AJAX!");  }var url="ajax.php?what=month&with="+switchTo;xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);xmlhttp.send(null);}function stateChanged(){		if(xmlhttp.readyState == 4){		var xmlDoc=xmlhttp.responseXML.documentElement;		document.getElementById("calendar").innerHTML = xmlDoc.getElementsByTagName("calendar");	}}function GetXmlHttpObject(){if (window.XMLHttpRequest)  {  // code for IE7+, Firefox, Chrome, Opera, Safari  return new XMLHttpRequest();  }if (window.ActiveXObject)  {  // code for IE6, IE5  return new ActiveXObject("Microsoft.XMLHTTP");  }return null;}

And my ajax code:

<?php$what = $_GET['what'];switch($what){case "month": $month = $_GET['with'];if(!$month){	$month = date("m");}header('Content-Type: text/xml');		header('Pragma: no-cache');		echo '<?xml version="1.0" encoding="UTF-8"?>';		echo '<calendar>';if($_GET['month']){	$thismonth = $_GET['month'];} else {   // get this month and this years as an int	$thismonth = ( int ) date( "m" );}	$thisyear = date( "Y" );		// find out the number of days in the month	$numdaysinmonth = cal_days_in_month(CAL_GREGORIAN, $thismonth, $thisyear);		// create a calendar object	$jd = cal_to_jd( CAL_GREGORIAN, $thismonth,date( 1 ), date( "Y" ) );		// get the start day as an int (0 = Sunday, 1 = Monday, etc)	$startday = jddayofweek( $jd , 0 );	$nextmonth = $thismonth + 1;	$nextmonthname = cal_to_jd(CAL_GREGORIAN, date($nextmonth),date(1), date("Y"));	$lastmonth = $thismonth - 1;	$nextmonthname = cal_to_jd(CAL_GREGORIAN, date($lastmonth),date(1), date("Y"));	// get the month as a name	$monthname = jdmonthname( $jd, 1 );	echo '	<table>		<tr>			<td colspan="7"><div align="center"><a href="java script:switchMonth('.$lastmonth.', '.$thismonth.');"><img src="back.png" width="12" height="12" border="0" /></img></a><strong>'.$monthname.'</strong><a href="index.php?month='.$nextmonth.'" title="'.$nextmonthname.'"><img src="forward.png" width="12" height="12" border="0" /></img></a></div></td>		</tr>		<tr>			<td><strong>S</strong></td>			<td><strong>M</strong></td>			<td><strong>T</strong></td>			<td><strong>W</strong></td>			<td><strong>T</strong></td>			<td><strong>F</strong></td>			<td><strong>S</strong></td>		</tr>		<tr>'; 	// put render empty cells 	$emptycells = 0; 	for( $counter = 0; $counter <  $startday; $counter ++ ) {			echo "\t\t<td>-</td>\n";		$emptycells ++;		}		// renders the days		$rowcounter = $emptycells;	$numinrow = 7;		for( $counter = 1; $counter <= $numdaysinmonth; $counter ++ ) {			$rowcounter++;				echo "\t\t<td>$counter</td>\n";				if( $rowcounter % $numinrow == 0 ) {					echo "\t</tr>\n";						if( $counter < $numdaysinmonth ) {							echo "\t<tr>\n";						}					$rowcounter = 0;				}		}	$numcellsleft = $numinrow - $rowcounter;		if($numcellsleft != $numinrow) {			for( $counter = 0; $counter < $numcellsleft; $counter ++ ) {					echo "\t\t<td>-</td>\n";			$emptycells ++;				}		}		echo "		</tr>	</table>";		echo "</calendar>";	break;}	?>

Thanks for any help and thanks for viewing.

Link to comment
Share on other sites

It's because the code isn't being parsed as HTML, it's being parsed as XML, and XML requires closing tags for all elements.Try responseText instead of responseXML.

Link to comment
Share on other sites

Now it's expecting a closing anchor tag. Do i need to change anything in "var xmlDoc=xmlhttp.responseText.documentElement;"?These are the errors that I'm getting:errorscreen.gif
It sounds like you closed another tag before closing the <a> tag. However, unless you're returning XHTML I don't recommend the responseXML property. You should find a different way to send data back, like JSON, or plain text which you can parse yourself later.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...