SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem: IE duplicate request with ajax

    I am having an incredibly hard time with a particular web application of mine. The problem appears to only be happening in IE, in which duplicate requests are issued. The funny thing is I randomly append something on the Http object opens url (random number), and im getting the same number on both requests according to Fiddler. This is really quite weird. The javascript (and full fiddler results for the area showing the bug) is available here http://paste.css-standards.org/26092. A quick sample for those that dont want to wade through the results:

    200 HTTP /app/embed/pjnavigator.php?&r=1613251236161361231
    200 HTTP /app/alert/login.php?&r=35616235612313551235
    200 HTTP /app/embed/pjnavigator.php?&r=1613251236161361231

    The second pjnavigator result came in about 8 seconds later. the function doing this (placed into the onload() of the page) is located in the javascript in the link above.

    Any ideas would be greatly appreciated!

    Richard

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure why you're getting two requests - might need to see more code for that.

    As to why you're getting the same number duplicated - I believe that your closure is incorrectly formed. I haven't tested it but give this code - or something similar - a try:
    Code:
    function updatenav(){
            /* Create Variables */
            var xmlHttp = getHttpObj();
            var xmlHttpX = getHttpObj();
            var pjAp = document.getElementById('project_dd');
            var tnav = document.getElementById('pjnav');
            var navstate = [];
            var selected_id = null;
            if(tnav_curselection != null)
            {
                    selected_id = tnav_curselection.id;
            }
            for(var i=0; i<tnav.childNodes.length; i++){
                    var child = tnav.childNodes[i];
                    if(obj_contains_class(child, "ti_bookopen")){
                            navstate[navstate.length] = child.id.substr(4);
                    }
            }
            
            setHandler1(xmlHttp, tnav, navstate);
            
            setHandler2(xmlHttpX, pjAp, xmlHttp);
            
            xmlHttpX.open("GET","embed/pjnavigator.php?&r=" + Math.random(),true);
        		
        		xmlHttpX.send(null);
    }
    
    function setHandler1(xh, tn, ns) {
    	xh.onreadystatechange = function () {
    		doHandler1(xh, tn, ns);
    	}
    }
    
    function doHandler1(xmlHttp, tnav, navstate) {
      /* HANDLER FOR THE NAVIGATION PANEL */
    	if (xh.readyState == 4) {
    		if(xmlHttp.responseText=="REQLOGIN"){
    		        // We need to login first.
    		        jsalert_open("alert/login.php?");
    		}
    		else
    		{
    		        tnav.innerHTML=xmlHttp.responseText;
    		        for(var b=0; b<navstate.length; b++){
    		                tnav_dblclick("sec_" + navstate[b]);
    		        }
    		        tnav_curselection = document.getElementById(selected_id);
    		        if(tnav_curselection != null)
    		                tnav_curselection.style.fontWeight = "bold";
    		}		
    	}
    }
    
    function setHandler2(xh, pj, xh2) {
    	xh.onreadystatechange = function () {
    		doHandler2(xh, pj, xh2);
    	}
    }
    
    function doHandler2(xmlHttpX, pjAp, xmlHttp) {
      /* HANDLER FOR THE DROP DOWN LIST, HANDLES THE NAV PANEL ASWELL */
    	if(xmlHttpX.readyState==4)
    	{
    	  if(xmlHttpX.responseText=="REQLOGIN"){
    	    // We need to login first.
    	    jsalert_open("alert/login.php?");
    	  }
    	  else
    	  {
    	    pjAp.innerHTML=xmlHttpX.responseText;
    	    // Now do the navigator
    	    xmlHttp.open("GET","embed/navigator.php?&r=" + Math.random(),true);
    			xmlHttp.send(null);
    	  }
    	}
    }

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Solved

    Actualy, I already solved the problem. It is, apparently, actually a bug in internet explorer! The double requests happen when IE encounters certain cache-control mechanisms. One of the mechanisms added with php's session-start. By simply clearing these mechanisms, IE no longer duplicated the request, and everything ran smoothly.

    PHP adds the following cache control policies by default with session_start

    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

    This I verified with Fiddler.

    I believe that must-revalidate is the policy that is causing the problem, though I could be mistaken. IE's implementation of xmlHttpResponse incorrectly requests said object twice upon encountering one of these cache-control mechanisms. I should note that the AJAX handler in this case only receives one of the requests, the other is silently discarded by IE. I dont believe this could possibly be the appropriate behavior and I will be releasing a bug report to the IE team later tonight.

    If you wish to duplicate this, simply create a simple ajax request however you wish, setting the target destination to be a PHP file that utilizes session_start(), and outputs SOMETHING, ANYTHING. You will only recieve the response once from your handler, but the server side code will be executed and returned twice (the later invisible) to the client.

  4. #4
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Any update regarding the IE bug

    I'm seeing the same issue as rpcesar is.

    rpcesar, did you get any further information about the duplicate requests.

    Did you end up filing a bug upstream at MS?


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
  •