Jump to content

Not a function ... why????????????


nloding

Recommended Posts

Here's how I call this code ... it's my wrapper for Ajax:

 

var ajax = new XMLHttp();
ajax.get('myscript.php?variable=value');

 

When I run that, I get the error in Firefox's Error Console that ajax.get is not a function.  So I've checked this code ten times and I see nothing wrong.  It's almost copied exactly from an example I saw online, and that example works (so says the author, it's from About.com).  Here's all the pertinent javascript code:

 

function XMLHttp() {
if (window.XMLHttpRequest) { // If we have a Gecko browswer?
	return new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE is more difficult ...
	var avers = ["Microsoft.XmlHttp", "MSXML2.XmlHttp", "MSXML2.XmlHttp.3.0",  "MSXML2.XmlHttp.4.0", "MSXML2.XmlHttp.5.0"];
	for (var i = avers.length -1; i >= 0; i--) {
		try {
			httpObj = new ActiveXObject(avers[i]);
			return httpObj;
		} catch(e) {}
	}
}    

// And what if the the browser sucks?
alert("Your broswer is too old. Consider upgrading!");
}

XMLHttp.prototype.get = function(url, element) {
this.open('GET', url, true);
this.onreadystatechange = function() {
	this.processRequest(element);
}
this.send(null);
}

XMLHttp.prototype.processRequest = function(element) {
if (this.readyState == 4 && this.status == 200) {
	findElement(element).innerHTML = this.responseText;
}
}

function findElement(target) {
var targetElem = document.getElementById(target);

if(!targetElem) {
	targetElem = getElementsByClassName(document, "*", target);
}

return targetElem;
}

 

The XMLHttp() function works fine, as I can use ajax.open and ajax.onreadystatechange.  But I can't use ajax.get ... I've tried calling the XMLHttp() function without "new" before it ...

 

I'm lost ... what's wrong with that code?

 

 

Link to comment
Share on other sites

Yeah, that's totally not fair!

 

I keep getting the 0x80040111 Firefox error because for some reason my abort() commands aren't killing my Ajax connection ... so I get weird errors and timeouts when calling the Ajax object more than once.  I'm wondering if that's the reason.  But if I close the browser, clear all private data, and try again, same deal -- same error "ajax.get is not a function".

 

I'm totally lost.  There's nothing wrong with that code.  I'll change my "ajax" var to "myObj", and "XMLHttp" to "reqObj" or something and see what happens, but that shouldn't make a difference.  Those aren't restricted names.

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.