Results 1 to 7 of 7

Thread: Solution to Ajax Includes Script Caching Error in Firefox 3?

  1. #1
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Solution to Ajax Includes Script Caching Error in Firefox 3?

    Ajax Includes Script
    http://www.dynamicdrive.com/dynamici...axincludes.htm

    I have been using the fantastic Dynamic Drive AJAX includes script for left-hand column navigation for years now, and it's a great script. Thank you for all the hard work creating it.

    Unfortunately, with Firefox 3 it sometimes "throws" the content displayed by the script from the left-hand column into the middle or end of the main content (rather than inserting it where coded). Refreshing the page or even just clicking back and then forward again makes the script display properly. This post from the DD Forums describes a similar problem with the same script but no one really posted an acceptable solution.

    From Googling, I also found this blog post which explains this type of behavior likely is caused by a bug in Firefox 3 related to caching static content. It appears that Firefox 3 has a number of related bugs.

    Has anyone discovered an acceptable solution to this problem? Thank you.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'd want to see a demo of the problem. Where do I have to go, and what do I have to do to make it happen? Is it repeatable, or does it only happen sometimes?

    Anyways, if the problem is caching of the imported content, use this code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function loadXmlHttp(url, id, bust) {
    var f = this;
    f.xmlHttp = null;
    /*@cc_on @*/ // used here and below, limits try/catch to those IE browsers that both benefit from and support it
    /*@if(@_jscript_version >= 5) // prevents errors in old browsers that barf on try/catch & problems in IE if Active X disabled
    try {f.ie = window.ActiveXObject}catch(e){f.ie = false;}
    @end @*/
    if (window.XMLHttpRequest&&!f.ie||/^http/.test(window.location.href))
    f.xmlHttp = new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari, others, IE 7+ when live - this is the standard method
    else if (/(object)|(function)/.test(typeof createRequest))
    f.xmlHttp = createRequest(); // ICEBrowser, perhaps others
    else {
    f.xmlHttp = null;
     // Internet Explorer 5 to 6, includes IE 7+ when local //
    /*@cc_on @*/
    /*@if(@_jscript_version >= 5)
    try{f.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
    catch (e){try{f.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){f.xmlHttp=null;}}
    @end @*/
    }
    if(f.xmlHttp != null){
    f.el = document.getElementById(id);
    if(bust)
    bust = (loadXmlHttp.re.test(url)? '&' : '?') + 'loadxmlhttpbust=' + new Date().getTime();
    f.xmlHttp.open("GET",url + (bust || ''),true);
    f.xmlHttp.onreadystatechange = function(){f.stateChanged();};
    f.xmlHttp.send(null);
    }
    else alert('Your browser does not support AJAX!'); // substitute your desired request object unsupported code here
    }
    
    loadXmlHttp.re = new RegExp('\\?');
    
    loadXmlHttp.prototype.stateChanged=function () {
    if (this.xmlHttp.readyState == 4 && (this.xmlHttp.status == 200 || !/^http/.test(window.location.href)))
    	this.el.innerHTML = this.xmlHttp.responseText;
    }
    </script>
    </head>
    <body>
    <div id="test">
    
    </div>
    <script type="text/javascript">
    new loadXmlHttp('external.htm', 'test', true);
    </script>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you for the code, John, it is much appreciated.

    The problem is inconsistent and I haven't noticed any particular pattern, which makes it a pain to troubleshoot, but you may go to the site and browse around using Firefox 3 if you have the time.

    Eventually one of the left hand side navigation elements that loads via the Ajax includes script will be thrown into the main column. If you see two horizontal rules without text in between them, that is the indicator that something is amiss and you can then look toward the middle or bottom of the main column to find the links that should have been displayed in the left hand column.

    This post indicates that other users are having the same issue with the same script in FF 3.

    My code is far from flawless, and it is heavily hacked to work with IE 5/6 for Windows and IE 5 for the Mac -- to support legacy MacOS 9 users -- but it has worked perfectly for years and has only suddenly become a problem with FF 3.

    If you spot something that I have overlooked, please let me know. Thanks again!

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well I couldn't get it to misbehave. I did surf on over to your host's (MacHost) page. The offer PHP. A PHP include would be better than any AJAX include and shouldn't have this problem.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    It doesn't misbehave consistently, you might have to view 20 pages or more. I'd rather not go the PHP route, but thanks for the suggestion.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Then try out the code I wrote. It works pretty much the same, you just need a container as shown. You may use it as many times as you like on a page, each with its own unique container.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. The Following User Says Thank You to jscheuer1 For This Useful Post:

    bdkyle (01-23-2009)

  8. #7
    Join Date
    Jun 2006
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Okay -- will investigate both routes. Thanks again!

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
  •