Avatar of Paul_Jarrett

asked on 

Ajax function unable to get object properties

I am trying to knock up a little Ajax-y method or two, just something nice, simple and reusable. All it should do is take the resonse and vomit it into the innerHTML of whatever element you specify. What I have works a treat in Firefox however Internet Explorer errors with the typically useful text

this.objElement is null or not an object.

I'm guessing this is something to do with the fact the function is called from the readyStateChange Handler so the object is recreated in a fresh instance? ...thou now I've guessed I'm sure you'll make me look silly....

Thanks for your help
sendBaseRequest( 'index.php', document.getElementById('myDiv'));
function sendBaseRequest(address, output) {
	http.open('get', address);
	a = new baseHandler();
	a.setTarget( output );
 	output.style.display = 'block'
	http.onreadystatechange = a.handler;
baseHandler = function(){
	baseHandler.prototype.setTarget = function( objElement ){
//		I'm sure it should be this way round, but the browser knows what it likes...
//		this.objElement = objElement;
		this.handler.objElement = objElement;
	baseHandler.prototype.handler = function(){		
		if(http.readyState == 4){
		var response = http.responseText;
			this.objElement.innerHTML = response;

Open in new window

Web BrowsersAJAXJavaScript

Avatar of undefined
Last Comment

8/22/2022 - Mon