Site menu:

Links:

RSS .NET RSS

RSS Engadget

Site search

Categories

September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  

Tags

Blogroll

XML http object cross browser

I believe this will be useful for everyone who wants to implement AJAX manually and make it compatible cross browser.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<script type="text/javascript"> 
 
           // cross-browser method to retrieve an XMLHttp object for asynchronous requests & responses
            function GetHTTPRequest()
            {
                var http_request = false;
 
                if (window.XMLHttpRequest) 
                { 
                    // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
 
                    if (http_request.overrideMimeType) 
                    {
                        http_request.overrideMimeType("text/xml");
                    }
                } 
                else if (window.ActiveXObject) 
                { 
                    // IE
                    try 
                    {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } 
                    catch (e) 
                    {
                        try 
                        {
                            http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } 
                        catch (e) {}
                    }
                }
 
                return http_request;
            }
 
</script>

Write a comment