Jump to content

allandlewis

Members
  • Posts

    4
  • Joined

  • Last visited

Posts posted by allandlewis

  1. It could be saying that anything in the expression is undefined, not necessarily the XML object. Try alerting each thing to figure out which is not defined.alert(xmlDoc);alert(xmlDoc.getElementsByTagName("hometown"));alert(xmlDoc.getElementsByTagName("hometown")[0]);alert(xmlDoc.getElementsByTagName("hometown")[0].childNodes);alert(xmlDoc.getElementsByTagName("hometown")[0].childNodes[0]);alert(xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue);This line alone:xmlDoc=xmlhttp.responseXML;Is not going to set xmlDoc to an object, at that point it's just a string. You need to explicitly create a new object, I think the object you're looking for is a DOMDocument object but I could be wrong.
    in IE alert(xmlDoc); returns object alert(xmlDoc.getElementsByTagName("hometown")); returns object alert(xmlDoc.getElementsByTagName("hometown")[0]); returns null it doesnt matter which fireld i refer to note: 1. all other browsers work fine 2. this program is identical (i think) to the w3schools program PHP - AJAX responseXML
  2. i have an html page, javascript page and a PHP pageeverything works fine on Firefox, Chrome and Safari however in IE i getan error "object required" on line 35 in the javascript pageline 35 is alert(xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue);i.e. the first reference to the xmlDoc object!!i am using IE 8, and PHP 5.3 on Windows 7 Ultimatethe pages are : HTML page HTMLPage.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type" /><script type="text/javascript" src="responsexml.js"></script><title>Untitled 1</title></head><body><form>Select a User:<select name="users" onchange="showUser(this.value)"><option value="1">Peter Griffin</option><option value="2">Lois Griffin</option><option value="3">Glenn Quagmire</option><option value="4">Joseph Swanson</option></select></form><h2><span name="firstname" id="firstname"></span> <span name="lastname" id="lastname"></span></h2><span name="job" id="job"></span><div style="text-align: left"> <span id="age_text"></span> <span name="age" id="age"></span> <span id="hometown_text" ></span> <span name="hometown" id="hometown"></span></div> </body>the JAVASCRIPT page responsexml.jsvar xmlhttp;var xmlDocfunction showUser(str){xmlhttp=GetXmlHttpObject();if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; }var url="responsexml.php";url=url+"?q="+str;url=url+"&sid="+Math.random();xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET",url,true);//xmlhttp.open("POST",url,true);//xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");xmlhttp.send(null);}function stateChanged(){if (xmlhttp.readyState==4) { if (xmlhttp.status==200) { xmlDoc=xmlhttp.responseXML; alert(document.getElementById("firstname").innerHTML); alert(xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue); document.getElementById("firstname").innerHTML= xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue; document.getElementById("lastname").innerHTML= xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue; document.getElementById("job").innerHTML= xmlDoc.getElementsByTagName("job")[0].childNodes[0].nodeValue; document.getElementById("age_text").innerHTML="Age Is --====-- : "; document.getElementById("age").innerHTML= xmlDoc.getElementsByTagName("age")[0].childNodes[0].nodeValue; document.getElementById("hometown_text").innerHTML="<br/>From Address --====-- : "; document.getElementById("hometown").innerHTML= xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue; } }}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;}the PHP page responsexml.php<?php$q=$_GET["q"];$serverName = "(local)";$connectionOptions = array("Database"=>"TestPHP");$conn = sqlsrv_connect( $serverName, $connectionOptions);if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); //die('Could not connect: ' . sqlsrv_errors()); }$sql="SELECT FirstName, LastName, Age, Hometown, Job FROM [user] WHERE id = $q " ;$result = sqlsrv_query($conn, $sql, array( $q ) );header("Content-type:text/xml");header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");header("Cache-Control: no-cache");header("Pragma: no-cache");$response='<?xml version="1.0" encoding="ISO-8859-1"' . chr(63) . chr(62) . " <person>";while($row = sqlsrv_fetch_array($result)) { $response = $response . "<firstname>" . $row['FirstName'] . "</firstname>"; $response = $response . "<lastname>" . $row['LastName'] . "</lastname>"; $response = $response . "<age>" . $row['Age'] . "</age>"; $response = $response . "<hometown>" . $row['Hometown'] . "</hometown>"; $response = $response . "<job>" . $row['Job'] . "</job>"; }$response = $response . "</person>";echo $response;sqlsrv_close($conn );?> any ideas ??--------------------------------------------------------------

×
×
  • Create New...