Click here to Skip to main content
15,898,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote ajax code like this,it is not working in IE but working in chrome,mozilla


please provide same code in jquery

C#
function AJAXRequest(url, callback) {

    var req = init();
    req.onreadystatechange = processRequest;
/*
    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
*/
    function init() {
        var xmlreq = false;
        if (window.XMLHttpRequest) {
            // Create XMLHttpRequest object in non-Microsoft browsers
            xmlreq = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            // Create XMLHttpRequest via MS ActiveX
            try {
                // Try to create XMLHttpRequest in later versions
                // of Internet Explorer
                xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e1) {
                try {
                    // Try version supported by older versions
                    // of Internet Explorer
                    xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e2) {
                    doError(e2);
                }
            }
        }
        return xmlreq;
    }

    function processRequest () {
      if (req.readyState == 4) {
        if (req.status == 200) {
          if (callback) callback(req);
        }
      }
    }

    this.doGet = function() {
      req.open("GET", url, true);
      req.send(null);
    }

    this.doPost = function(body) {
      req.open("POST", url, true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      req.send(body);
    }
}
Posted
Updated 17-Jul-12 23:15pm
v2

1 solution

Never do this. Use jquery to wrap the differences between browsers up for you. Your code does not work in IE, but, jquery contains the code needed, and you can call a common method for all browsers.
 
Share this answer
 
Comments
kesavahariprasad 18-Jul-12 1:31am    
but in our project jquery is not using
Christian Graus 18-Jul-12 1:37am    
That would be my point. Your project is outdated and doing the wrong thing. jQuery is free, so add it and use it. You may need to ask for permission first, but only an idiot would refuse you the right to use the right tools for the job.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900