SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Ajax in IE < v7

  1. #1
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax in IE < v7

    Hello,

    I have a IE issue to resolve. Using the code found here, http://www.wrgd.com/assets/js/ajax-get-set.js, my AJAX calls send and recieve fine in FF and IE 7, but in earlier IE versions like 6.0.2900..... especially it fails. All it returns is "Started..." which is at line 87. How can i make this work in IE < v7?

    There has to be a fix out there. Thanks for all your help.

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These two functions work fine in IE5.5+, FF, OP, SA, NS, SM, IC...
    One is used for the method POST (AjaxPOST), the other is for GET (AjaxGET).

    Code JavaScript:
    function AjaxGET()
    {
        var xhReq = createXMLHttpRequest();
        var busy = false;
        var responseFunction = null;
        var response = null;
     
        function createXMLHttpRequest( ) {
            try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
            try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
            try { return new XMLHttpRequest( ); } catch(e) {}
            alert("XMLHttpRequest not supported");
            return null;
        }
     
        this.getData = function(URL,onResponse)
        {
            if (!busy){
                busy = true;
                xhReq.open("GET", URL, true);
                xhReq.onreadystatechange = respFunction;
                responseFunction = onResponse;
                xhReq.send(null);
            }
        }
     
        this.getResponse = function()
        {
            return response;
        }
     
        function respFunction()
        {
            if (xhReq.readyState == 4 && xhReq.status == 200){
                response = xhReq.responseText;
                busy = false;
                responseFunction();
            }
        }
     
        this.isBusy = function()
        {
            return busy;    
        }
    }
     
    function AjaxPOST()
    {
        var xhReq = createXMLHttpRequest();
        var busy = false;
        var responseFunction = null;
        var response = null;
     
        function createXMLHttpRequest( ) {
            try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
            try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
            try { return new XMLHttpRequest( ); } catch(e) {}
            return null;
        }
     
        this.getData = function(URL,data,onResponse)
        {
            if ( xhReq != null ){
                if (!busy){            
                    response = '';
                    busy = true;
                    responseFunction = onResponse;
                    xhReq.open("POST", URL, true);
                    xhReq.onreadystatechange = respFunction;
                    try {
                        xhReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                        xhReq.setRequestHeader("Content-length", data.length);
                        xhReq.setRequestHeader("Connection", "close");
                    }
                    catch(e) {
                        return false;
                    }
                    xhReq.send(data);
                    return true;
                }
                return true;
            }
            return false;
        }
     
        this.getResponse = function()
        {
            return response;
        }
     
        function respFunction()
        {
            if (xhReq.readyState == 4 && xhReq.status == 200){
                response = xhReq.responseText;
                busy = false;
                responseFunction();
            }
        }
     
        this.isBusy = function()
        {
            return busy;    
        }
    }

    Example:
    Code JavaScript:
    var dataprovider = new AjaxPOST();
    dataprovider.getData('js/feed.php', '[b]&name=hexburner&page=5[/b]', function(){
        alert(dataprovider.getResponse());
    });
     
    var dataprovider2 = new AjaxGET();
    dataprovider2 .getData('js/feed.php[b]?name=hexburner&page=5[/b]', function(){
        alert(dataprovider2 .getResponse());
    });
    FOR SALE: 1 set of morals, never used, will sell cheap

  3. #3
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your idea. i did find another solution without using all new scripts.

  4. #4
    SitePoint Addict
    Join Date
    Jun 2005
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •