Mark Benussi wrote:
I havent heard of one. Its only Javascript at the end of the day!

Yeah, right!

--
Martin Cooper


Here are some methods I have in an ajax.js and some example code to invoke the code.

ajax.js

/**
* Returns an XMLHttpRequest object based on the client platform
*/
function getXMLHttpRequest() {
    var newRequest = null;
    if (window.XMLHttpRequest) {
        // Non-IE browsers
        newRequest = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // IE
        newRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return newRequest;
}
/**
* Indicates if the request is of a ready state
*/
function isResponseReady() {
    return request.readyState == 4;
}

function ifHttpStatusOK() {
    return request.status == 200;
}

function getResponseText() {
    return request.responseText;
}

function getResponseXML() {
    return request.responseXML;
}

function getResponseStatusText() {
    return request.statusText;
}

/**
* The global variable request object
*/
var request = null;

/**
* Returns a response for the requested url.
*/
function getResponseForRequestUrl(url, method) {

    request = getXMLHttpRequest();
    request.onreadystatechange = method;
    try {
        request.open("GET", url, true);
        if (window.ActiveXObject) {
            // IE
            request.send();
        }
    } catch (e) {
        // @TODO Log the issue
        alert(e);
    }
    if (window.XMLHttpRequest) {
        // Non-IE browsers
        request.send(null);
    }
}

function invokeRequestUrl(url) {
    getResponseForRequestUrl(url, function() {});
}

example client side code.

// Load the Shop categories document
getResponseForRequestUrl('/ajax/shop_module/preferences/kelkoo.do?dispatch=loadShopCategories', shopCategoriesReturned);

/**
* Invoked when the Shop categories have been returned
*/
function shopCategoriesReturned() {

    if (isResponseReady()) {
        // At this point the response will be ready
        if (!ifHttpStatusOK()) {
            // @TODO Log the issue
            var statusText = getResponseStatusText();
        } else {
            // Correct response
            var shopNavigationDocument = getResponseXML();

            // Now work with the document
        }
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to