Jump to content

http.responseXML is null


Muddy_Funster

Recommended Posts

OK, I've been encouraged to start and include Ajax in some new site development.  Problem is, I've never touched it before so I suck at it, so silly little problems like this bugger me up.  I'm trying to get a login form to validate and return xml output that is then displayed in div by the ajax function.  I get the "http.responseXML is null" error when I try and do this.  I have pretty much copy/paste and then edited code snippets off the net to get this far, and I'm starting to get my head arround what does what and where it does it, but I can't find what the problem is with this.

 

the script code is:

// JavaScript AJAX Document

var http = createRequestObject();

function createRequestObject() {
// find the correct xmlHTTP, works with IE, FF and Opera
var xmlhttp;
try {
  	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e) {
    try {
    	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e) {
    	xmlhttp=null;
    }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
return  xmlhttp;
}


function GetID(uName, uPass){
var name = uName;
var pass = uPass;
if(name.length >0 && pass.length >0) {
	name=escape(name);
	pass=escape(pass);
try{
    http.open("GET", "inc/login.php?name="+name+"&password="+pass, true);
    http.setRequestHeader('Content-Type',  "text/xml");
    http.onreadystatechange = handleResponse;
	http.send(null);
}
catch(e){
	// caught an error
	alert('Request send failed.');
}
finally{}
} else {
	alert("please complete both fields");
}
}
  
function handleResponse() {
try{
if((http.readyState < 4)||(http.status != 200)){
    var ajaxDisplay = document.getElementById('main');
		ajaxDisplay.innerHTML = '<BR><BR><center><img src="./img/loading6.gif" alt="Loading..."><BR>Loading...</center>';
    }
    if((http.readyState == 4)&&(http.status == 200)){
    	var response = http.responseXML.documentElement;
    	var n = response.getElementsByTagName('message')[0].firstChild.nodeValue;
    	var e = response.getElementsByTagName('status')[0].firstChild.nodeValue;
    	var r = response.getElementsByTagName('contnent')[0].firstChild.nodeValue;

    	// write out response
      document.getElementById("main").innerHTML = r;
      alert(n);
	}
  }
catch(e){
	// caught an error
	alert('Response failed. >>'+e);
}
finally{}
}

 

the login.php file (still commented from when I was checking it in browser)

<?php
/*
@SESSION_START();
require_once './connection.php';
$name = mysql_real_escape_string($_GET['name']);
$pass = mysql_real_escape_string($_GET['password']);
$logSQL = "SELECT branchNo FROM branch WHERE authLogin ='$name' AND branchPass = '$pass'";
$logCHK = mysql_query($logSQL);
if(mysql_num_rows($logCHK) <> 1 ){
*/
print "<?xml version='1.0' encoding='ISO-8859-1'?>
<xml>
  <status>F</status>
  <message>Either your login ID or password are incorect, please try again</message>
  <content><?php require_once 'first_check.php'; ?></content>
</xml>";
/*
}
else{
$logRES = mysql_fetch_array($logCHK);
echo "Login Successfull";
$_SESSION['id'] = $logRES['branchNo'];
print "<?xml version='1.0' encoding='ISO-8859-1'?>
<xml>
  <status>Y</status>
  <message>Loggin Succsessful</message>
  <content><?php require_once 'first_check.php'; ?></content>
</xml>";

}*/
?>

 

and the page with the login form:

<?php 
if (!isset($_SESSION['id'])){
?>
<div id="login">
<form action="#" name ="login" method="post">
  <center>Login:<br />
  Login ID:  <input type="text" name="name" id="name" value=""><br><br>
  Password: <input type="password" name="password" id="password" value=""><br>
  <input type="button" alt="Login" value="Login" onclick="GetID(login.name.value, login.password.value)">
  </center>
</form>
</div>
</p>Welcome to the new McConechy's Intranet Site.  Updates and construction are still ongoing at the moment, with only some of the site operational.</p>
<p> To Access most feetures you are requred to log in.  this is both to maintain security, and also to identify you on the site.</p>
<?php
}
else{
print " You are Logged In.  Updates and construction are still ongoing at the moment, with only some of the site operational.
Please use the buttons on the left to navigate.
";
}
?>

 

I have checked the generated XML and it's fine as far as any validators are concerned, I also checked the link in firebug when the error comes up and it contains the xml as it should be, with nothing additional/erronious that I can see.  I have the type set to text/xml (as you can see in the code) and have checked the login.php directly in the browser and it is producing the data as it should.

 

This is still very early development so it's a good bit messy, that will be deat with in due course, but I sure would appreciate some assistance on this one.

Link to comment
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.