Forums

This topic is locked

AJAX query- need help: xmlhttp has no properties

Posted 09 Sep 2007 15:04:47
1
has voted
09 Sep 2007 15:04:47 Kenneth Halley posted:
Hi
Hope someone with a bit AJAX/Javascript knowledge can help me. I have been building a php based application which works well (its a online booking system) but I was concious that it needed some cleverer coding to improve server side performance.
So I have decided to use a little bit AJAX to load some content into my page on demand rather than when the page initialises. This should give me a 14 fold reduction in database hits. A good thing.

I am no javascript expert so pretty much use code I can find in text and things- and have used some of this particular code elsewhere before with no issues. However here I am getting a strange error that appears to only afflict Firefox, ie7 works fine - just as I intended.

To see what I mean- check out this page in ie7
www.halleynet.com/bookings/new_booking.php?c=s

click on a date field and you will get a table which shows availability. (don't worry about formatting and stuff- its a development system and I am still working on it). The table is loaded via ajax- by calling a file on the server that produces the table.

Do the same in Firefox and I get the error:
xmlhttp has no properties
makerequest("includes/ajaxquery.php?c=s&base=1189292400", "1189338639"functionsx.js (line 97)
onclick(click clientX=0, clientY=0)new_booking.php (line 1)
[Break on this error] xmlhttp.open("GET", serverPage);

the function makerequest is associated with the date link onthe page and has the onclick behaviour.
Make request expects two parameters- the url to get the content, and the id of the div to place it in
You can see in the error both are there- the number ending 639 is dynamically generated and is the id of the div.

the functions i am using for the ajax are:

 /*AJAX http connector script*/
 function getxmlhttp() {
	var xmlhttp = null;
	if(window.xmlhttpRequest){
		try {
		xmlhttp = new xmlhttpRequest();
	} catch (e) { }
}else if (window.ActiveXObject) {
	try {
		xmlhttp = new ActiveXObject("Msxml2.xmlhttp");
	}catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.xmlhttp");
		} catch (e) { }
	}
}
return xmlhttp;
}


and


 /*ajax http request script*/
 function makerequest(serverPage, objID) {
	var xmlhttp = getxmlhttp();
	var obj = document.getElementById(objID);
       xmlhttp.open("GET", serverPage);														xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        	obj.innerHTML = xmlhttp.responseText;
	}
}
																	 xmlhttp.send(null);
}


Any help would be greatfully received as javascript is not my strongpoint and I am so close to achieving what I set out to do here- with it working in ie7.
cheers
Kenny


-----------------------------------
www.halleynet.co.uk

Replies

Replied 09 Sep 2007 15:10:49
09 Sep 2007 15:10:49 Kenneth Halley replied:
Actually- it just occurred to me to run this up in Opera and see what it does. Alas its not working there either but I seem to get a different error which might help:

JavaScript - www.halleynet.com/bookings/new_booking.php?c=s
Event thread: click
Error:
name: TypeError
message: Statement on line 97: Could not convert undefined or null to object
Backtrace:
Line 97 of linked script www.halleynet.com/bookings/includes/js/functionsx.js
xmlhttp.open("GET", serverPage);
Line 1 of script
makerequest("includes/ajaxquery.php?c=s&base=1189378800", "1189425998";
return false;
At unknown location
[statement source code not available]


-----------------------------------
www.halleynet.co.uk
Replied 09 Sep 2007 18:58:41
09 Sep 2007 18:58:41 Kenneth Halley replied:
Not to worry- sorted now!
Went back to some really basic test scripts I had and did some mixing of code from my test system to the test scripts and found the error in the makerequest handler.
The error was not as obvious as the firefox console seemed to indicate and its weird how ie did not seem to care.
heres the amended scripting- note there is some alert debug code in here commented out

 /*AJAX http connector script*/
var xmlhttp = false;
//Check if we are using IE.
try {
//If the Javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
/*alert ("You are using Microsoft Internet Explorer.");*/
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using Internet Explorer.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
/*alert ("You are using Microsoft Internet Explorer");*/
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
/*alert ("You are not using Microsoft Internet Explorer");*/
}

 /*ajax http request script*/
 function makerequest(serverPage, objID) {
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

Reply to this topic