views:

4085

answers:

4

I have this strange issue with my web app. You see, I'm using jQuery with the Forms API and doing $('#MyForm').ajaxSubmit(api parms and callback function goes here).

Randomly when I do this, however, and only on Firefox, the page load icon starts spinning, the page load progress bar runs in the status bar, and the stop button goes red -- but it has already posted the form and brought back a result. If I refresh the page and keep trying to do this, it randomly exhibits the problem, but not consistently.

This problem occurred on FF2 on Windows 2008 Server and FF3 on Ubuntu 8.04. The problem is not seen with IE6, IE7, Opera (latest stable, Nov 2008), or Safari (latest stable, Nov 2008).

Is this just a known bug in FF with AJAX, or is there something I can do with jQuery to stop the page load issue?

EDIT: This might have something to do with TinyMCE. I cannot confirm this 100%, but when I use jQuery to bring back a form with a TinyMCE control on it, the problem seems to exhibit itself more often. I tried doing it with a form that does not have a TinyMCE control on it, several times, and couldn't get the problem to occur. Again, that's nothing conclusive, but might be a factor.

EDIT: Okay, I just commented out the TinyMCE stuff and I can confirm that the problem goes away then. If I bring the TinyMCE control back, the problem randomly occurs.

A: 

Try to look at the server response, using firebug to see exaclty if there is a problem then, or if you have any javascript exception raising.

voyager
Firebug shows nothing unusual in the Net\XHR responses it receives. The responses look the same between the ones that work (no red stop button lingers) and ones that don't work (stop button lingers).Javascript raises no errors in the console or anything in Firebug that I can see.
A: 

I used to have this issue when I worked on a site that made heavy use of iframes. If I remember correctly an easy way to cure this is to create another iframe in the top page with minimum height/width and call it frameFix or similar.

Then from the Iframe content pages use a body load event to write an empty string then close the frameFix iframe. This forces the status bar to fully load up.

e.g

iframe content page

<body onload="javascript:progressBarHack()">

function progressBarHack(){
   top.frameFix.document.write("");
   top.frameFix.close();
   return;
}
redsquare
Thanks. Testing that now. I'm not using an IFRAME, but an AJAX call to load in new content, but I think I can do the document write and document close inside the response text that comes back from the ajax call.
It worked!!! I'm posting the answer in a more cleared-up way, but I give you credit for finding the answer.
Mike - I think the issue is that TinyMCE itself uses an Iframe. Not used it myself but I believe it would work like that.
redsquare
A: 

You probably don't want to upmod this answer -- I'm just extrapolating on redsquare's answer, which fixed me.

I was using AJAX (jQuery Form Plugin API and .ajaxSubmit(), to be exact) to pull back a form. When I hit Save or Cancel on that form, it was showing the red stop button in firefox and wouldn't stop.

So, to fix this, I need to take the calling page and add a hidden IFRAME in it like this:

<iframe frameborder="0" src="http://mysite.com/fixdoc.html" id="frameFix" height="1" width="1" style="position: relative; left: -500px"></iframe>

Then, I needed to create a fixdoc.html that was just an ordinary empty HTML page with the standard tag stuff in it.

Then, after Save or Cancel has fully completed in my logic, I need to execute this:

var ifr = document.getElementById('frameFix');
var doc = ifr.contentDocument;
if (doc == undefined || doc == null)
doc = testFrame.contentWindow.document;
doc.open();
doc.write(' ');
doc.close();

Somehow, this tells Firefox to get out of its infinite load loop.

A: 

I had this problem with this code that ran to set the value on an empty visible iframe:

function loadIframeContent() {
    $.post(
        '/my/content/url',
        $('#my-form').serialize(),
        function (data) {
            $('#my-preview-div-with-iframe').dialog('open');
            $('#id-on-my-iframe-tag')[0]
                .contentWindow
                .document
                .write(data);

            resizeIframeToContent();
        },
        'html'
    );
}

The solution turned out to be:

            var $document = $('#id-on-my-iframe-tag')[0]
                .contentWindow
                .document;    
            $document.open();
            $document.write(data);
            $document.close();

So in the end, the document.write(data) call is unchained so that first the document can be opened, then written, and then finally closed. Don't name the document variable document (at least not with Firefox 3) as it will collide -- use $document or similar.

I'm also using TinyMCE but this appears to be unrelated.

Cymen