Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2007, 07:19 PM
Registered User
 
Join Date: May 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to nloding Send a message via Yahoo to nloding
Default Not a function ... why?

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

Code:
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:

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?






Similar Threads
Thread Thread Starter Forum Replies Last Post
function keyvanjan ASP.NET 2.0 Professional 1 September 19th, 2007 10:22 AM
How to use Function akumarp2p SQL Server 2000 1 May 28th, 2007 05:04 AM
send variable in function to another function schoolBoy Javascript How-To 6 March 3rd, 2007 09:16 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.