Jump to content

[SOLVED] I am baffled as to why this is not working?


garethhall

Recommended Posts

Hey Guys,

 

I am stuffed if I know what is causing this page not to work I have now spend I don't know how many hours on it.

Please have a look and see if you can see what is wrong?

 

I keep on getting the "BAD" alert? but when I alert(xmlHttp.responseText) I get "ok" then how how come it is alerting "BAD" should it not be "GOOD"?

 

Initial PHP page code libEdtBook.php

 

<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="ajax/js/edtBook.js"></script>
</head>
<body>
<form name="frmAddBook" method="post">
<input type="button" name="updateTheBook" id="updateTheBook" value="Update book details" onclick="svBook()"/>
</form>
</body>
</html>

 

JS ajax code edtBook.js

 

var xmlHttp
function svBook(){
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null){
	alert("Browser does not support HTTP Request");
	return;
}
var qstr;
	xmlHttp.onreadystatechange = bookSaveResult;
xmlHttp.open("POST","ajax/edtBook.php?",true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send(qstr);
}

function bookSaveResult(){ 
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
	if(xmlHttp.responseText == "ok"){
		alert("GOOD");
	}else {
		alert("BAD");
	}
}

} 

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;}

 

PHP page Ajax is calling edtBook.php

 

<?php echo "ok" ?>

Archived

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

×
×
  • 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.