DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Ajax in IE 6

  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Exclamation Ajax in IE 6

    Hi guys,

    I'm trying to basic ajax program. The thing is, the program is working good in Firefox. In IE 6 the program behaves unexpectedly.


    The scenario is, whenever a user keys in some text, it retrieves the name similar to the text entered by the user. This ajax request happens on every keypress. This works as expected in Firefox. But, in IE 6, this works only for the first keypress. After that nothing seems to happen. When I checked the server log, the requests are logged. Here is the code.

    Code:
    /* test.js */
    
    String.prototype.ltrim = function() { return this.replace(/^\s+/, ''); }
    String.prototype.rtrim = function() { return this.replace(/\s+$/, ''); }
    
    function getXmlHttpObject()
    {
        var request = null;
    
        /* Does this browser support the XMLHttpRequest object? */
        if (window.XMLHttpRequest) {
            if (typeof XMLHttpRequest != 'undefined')
                /* Try to create a new XMLHttpRequest object */
                try {
                    request = new XMLHttpRequest( );
                } catch (e) {
                    request = null;
                }
        /* Does this browser support ActiveX objects? */
        } else if (window.ActiveXObject) {
            /* Try to create a new ActiveX XMLHTTP object */
            try {
                request = new ActiveXObject('Msxml2.XMLHTTP');
            } catch(e) {
                try {
                    request = new ActiveXObject('Microsoft.XMLHTTP');
                } catch (e) {
                    request = null;
                }
            }
        }
        return request;
    }
    
    function sendRequest(){
        if(xmlHttp == null){
            xmlHttp = getXmlHttpObject();
            
            if(xmlHttp == null) return;
        }
        
        var inputStr = document.getElementById("name").value;
        
        if(inputStr.ltrim() != ""){
            var url="handleAjax.do?name=" + inputStr.ltrim();
            xmlHttp.onreadystatechange=getResponse;
            xmlHttp.open('GET', url, true);
            xmlHttp.send(null);
        }
        document.getElementById("console").innerHTML="";
    }
    
    function getResponse(){
        if (xmlHttp.readyState==4){ 
            document.getElementById("console").innerHTML=xmlHttp.responseText;
        } 
    }
    Last edited by baskcoder; 01-23-2009 at 06:33 AM.

  2. #2
    Join Date
    Jan 2009
    Posts
    2
    With the help of alert boxes, I have noticed that after the first key press, there is no response. But the requests are sent. When the page is viewed in Firefox, the requests and responses are done as expected.

    Any idea how to troubleshoot this?

    Thanks.

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Have you tried it in IE7?

  4. #4
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    try this:
    Code:
        if(inputStr.ltrim() != ""){
            document.getElementById("console").innerHTML="";
            var url="handleAjax.do?name=" + inputStr.ltrim();
            xmlHttp.onreadystatechange=getResponse;
            xmlHttp.open('GET', url, true);
            xmlHttp.send(null);
        }
    }
    and tell me what's ur results?
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

Similar Threads

  1. Ajax and Browser Positioning
    By dbrook007 in forum AJAX
    Replies: 0
    Last Post: 04-22-2008, 07:40 AM
  2. Ajax within Ajax generated code
    By geekdesign in forum AJAX
    Replies: 2
    Last Post: 09-16-2007, 08:38 PM
  3. using an AJAX function to return a value
    By k285715 in forum AJAX
    Replies: 0
    Last Post: 06-18-2007, 11:06 AM
  4. Ajax: Working in IE but not Mozilla?
    By MarkMac in forum AJAX
    Replies: 0
    Last Post: 03-15-2007, 04:41 AM
  5. New forum + some AJAX links
    By Lori in forum AJAX
    Replies: 0
    Last Post: 02-09-2006, 02:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center