SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ajax and browser

    This code is working on Firefox and Opera. But it is not working on Internet Explorer:
    Code:
      
    <html><head>
    
    
    <script type="text/javascript">
    function http() {
    var http_nesnesi = null;
      try {
        http_nesnesi = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          http_nesnesi = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) {
          http_nesnesi = new XMLHttpRequest();
        }
      }
      return http_nesnesi;
    }
    
    http = new http();
    
    function istek_yolla(sayfa) {
      http.onreadystatechange = cevap;
      http.open("GET",sayfa);
      http.send(null);
    }
    
    function cevap() {
      if(http.readyState == 4) {
        document.getElementById('icerik').innerHTML = http.responseText;
      }
    }
    </script></head><body>
    
    <a href="#" onclick="istek_yolla('test1.htm');">Menu elemani 1</a> | 
    <a href="#" onclick="istek_yolla('test2.htm');">Menu elemani 2</a> | 
    <a href="#" onclick="istek_yolla('test3.htm');">Menu elemani 3</a> | 
    
    <br> <br> 
    
    <div id="icerik">sayfa-3 icerigi</div>
    
    </body></html>
    This code is working on Internet Explorer. But it is not working on Firefox and Opera:
    Code:
    <script type="text/javascript">
    var http;
    var browser = navigator.appName;
    getNewXMLHttpRequest()
    
    function getNewXMLHttpRequest() {
      var obj;
        try {
          // For Internet Explorer.
          http = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(e) {
          try {
            // Gecko-based browsers, Safari, and Opera.
            http = new XMLHttpRequest();
          }
          catch (e) {
            // Browser supports Javascript but not XMLHttpRequest.
            http = false;
          }
        }
        return http;
    }
    
    function Goster(s){
    document.getElementById("icerik").innerHTML="Loading...";
    
    if (s==1){
      var url="http://www.google.com.tr"; 
    }else if(s==2){
      var url="http://www.webdeveloper.com/";
    }else if(s==3){
      var url="http://www.sitepoint.com/";
    }else{
      var url="http://www.tomshardware.com.tr/";
    }
        http.open('get', url);
        http.onreadystatechange = icerikdegisim;
        http.send(null);
    }
    
    function icerikdegisim(){
        if(http.readyState == 4){
                document.getElementById('icerik').innerHTML = http.responseText;
            } else {
        }
    }
    </script>
    
    
    </head>
    <body>
    
    <a href="javascript:Goster(1);">google</a>
    <a href="javascript:Goster(2);">webdeveloper</a>
    <a href="javascript:Goster(3);">sitepoint</a>
    <a href="javascript:Goster(4);">tomshardware</a>
    
    <div id="icerik" >
    sayfa išeiği
    </div>
    I want, it works on Opera, Firefox and Internet Explorer. What can I add this?

  2. #2
    SitePoint Enthusiast panthro's Avatar
    Join Date
    Dec 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd try using a proven an tried library like sarissa to worry about browser compatibilities and let you get on with developing your app.

    Also check out some of the Sitepoint AJAX articles.


    Things to do When Bored

    My List of Classic Kids TV - Includes links to fansites

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,840
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Test for XMLHttpRequest(); support first so that IE7 uses that method of access rather than the activeX method that earlier IE versions require.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •