Ask a questionAsk a question
 

AnswerErratic AJAX timeout errors

  • Wednesday, November 04, 2009 4:39 PMmikegar Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I inherited a system that uses AJAX to maintain a "crumb trail" dropdown list at the bottom of an iFrame.  We get erratic, yet numerous AJAX timeout errors on a dynamically-created ashx file.  The user's history is stored in a database table, which is used to populate the dropdown list's entries.  We get this error many times in our production environment, but in our dev and staging environments not so much, mainly due, I suspect, to the difference in volume of users/transactions.

    I've been coding Javascript and ASP/.NET for some time now, but my experience with AJAX and iFrames is practically nil.  The implementation involves 3 functions - 2 Javascript and one ASP.NET/AJAX.  The iFrame onload event calls the AJAX function (whose function is to update the entries in the dropdown list), passing the result of another javascript function (called _callback, whose function seems to be to rebuild/update the dropdown list).

    The AJAX function pretty much just does a database read, but code snippets that may be relevant follow.  I know I'm aiming at a pretty wide target here, but does anyone see anything that might be causing a timeout, or at least tell *which* point in the process is timing out?  The strange thing is that it's not like you sit there for a long time waiting before the error occurs - it's amost instantaneous.

    <iframe id="MainIFRame" name="MainIFRame"
                src="<%= CurrentPageHTML %>" frameBorder="0" width="100%"
                scrolling=auto height="<%= (GlobalVar1.ScreenHeight-200) %>px"             
            application="no" onload="IFrame_Load();">
                                                </iframe>

    function IFrame_Load() {
            MyApp.RC_Navigation.RefreshHT(_callback);
            return true;

    function _callback(result) {
            var jumpSelect = document.getElementById('jumpDDL');
            for(var n=jumpSelect.length-1;n>=0;n--) {
                jumpSelect.options.remove(n);
            }
            var activeIdx = 0;
            var urlStr = "";
            if(result.error!=null)
                document.getElementById('NextBtn').innerHTML = result.error;
            for(var i=0; i<result.value.Rows.length; i++) {
                urlStr = result.value.Rows[i].PageUrl;
                if(urlStr.indexOf("?")>=0)
                    urlStr += "&HT=" + result.value.Rows[i].OrderNo;
                else
                    urlStr += "?HT=" + result.value.Rows[i].OrderNo;
                jumpSelect.options[i] = new Option(result.value.Rows[i].PageTitle, urlStr);
                if(result.value.Rows[i].Status=='Active') {
                    activeIdx = i;
                    jumpSelect.selectedIndex = i;
                }
            }
            if(activeIdx > 0) {
                urlStr = result.value.Rows[activeIdx-1].PageUrl;
                if(urlStr.indexOf("?")>=0)
                    urlStr += "&HT=" + result.value.Rows[activeIdx-1].OrderNo;
                else
                    urlStr += "?HT=" + result.value.Rows[activeIdx-1].OrderNo;
                document.getElementById('PrevBtn').href = urlStr;
                document.getElementById('PrevBtn').innerHTML = "&lt;&lt; " + result.value.Rows[activeIdx-1].PageTitle;
            }
            else {
                document.getElementById('PrevBtn').innerHTML = '';
            }
            if(activeIdx < result.value.Rows.length - 1) {
                urlStr = result.value.Rows[activeIdx+1].PageUrl;
                if(urlStr.indexOf("?")>=0)
                    urlStr += "&HT=" + result.value.Rows[activeIdx+1].OrderNo;
                else
                    urlStr += "?HT=" + result.value.Rows[activeIdx+1].OrderNo;
                document.getElementById('NextBtn').href = urlStr;
                document.getElementById('NextBtn').innerHTML = result.value.Rows[activeIdx+1].PageTitle + " &gt;&gt;";
            }
            else {
                document.getElementById('NextBtn').innerHTML = '';
            }
            return true;
        }

    Thanks!

Answers

All Replies