javascript - Fixing theIE 12030 repeatability bug for Ajax calls - Stack Overflow

I just loop my Ajax call until the 12030 error goes away.The error is reported as a bug hereDoes anyo

I just loop my Ajax call until the 12030 error goes away. The error is reported as a bug here

Does anyone know if there is a better fix...as this takes up time to loop. I read this was a known issue with IE that it intermittently produces 12030 errors as that Ajax status.

var Ajax = {
    createAjaxObject: function()
    {
        var request;
        try
        {
            request = new XMLHttpRequest();
        }
        catch(error)
        {
            try 
            {
                request = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(error)
            {
                try
                {
                    request = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(error)
                {
                    request = false;
                }
            }
        }
        return request;
    },

    useAjaxObject: function( path, param, ajax_func, html_div )
    {
        var object = new Ajax.createAjaxObject();
        object.open( "POST", path, true );
        object.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
        object.setRequestHeader( "Content-length", param.length );
        object.setRequestHeader( "Connection", "close" );
        object.onreadystatechange = function()
        {
            if( this.readyState === 4 )
            {
                if( this.status === 200 )
                {
                    ajax_func( this.responseText, html_div );
                }
                else
                {
                    Ajax.repeatUseAjaxObject( path, param, ajax_func, html_div );
                    return false;
                }
            }
        };
        object.send( param );
        return true;
    },
    repeatUseAjaxObject: function( path, param, ajax_func, html_div )
    {
        var state = false,
            count = 1;
        while(state === false && count <= 5)
        {
            state = Ajax.useAjaxObject( path, param, ajax_func, html_div );
            if( count !== 1 )
            {
                alert( 'Ajax Object Use Failed ');
            }
        count++;
        }
        return state;
    }

I just loop my Ajax call until the 12030 error goes away. The error is reported as a bug here

Does anyone know if there is a better fix...as this takes up time to loop. I read this was a known issue with IE that it intermittently produces 12030 errors as that Ajax status.

var Ajax = {
    createAjaxObject: function()
    {
        var request;
        try
        {
            request = new XMLHttpRequest();
        }
        catch(error)
        {
            try 
            {
                request = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch(error)
            {
                try
                {
                    request = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(error)
                {
                    request = false;
                }
            }
        }
        return request;
    },

    useAjaxObject: function( path, param, ajax_func, html_div )
    {
        var object = new Ajax.createAjaxObject();
        object.open( "POST", path, true );
        object.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
        object.setRequestHeader( "Content-length", param.length );
        object.setRequestHeader( "Connection", "close" );
        object.onreadystatechange = function()
        {
            if( this.readyState === 4 )
            {
                if( this.status === 200 )
                {
                    ajax_func( this.responseText, html_div );
                }
                else
                {
                    Ajax.repeatUseAjaxObject( path, param, ajax_func, html_div );
                    return false;
                }
            }
        };
        object.send( param );
        return true;
    },
    repeatUseAjaxObject: function( path, param, ajax_func, html_div )
    {
        var state = false,
            count = 1;
        while(state === false && count <= 5)
        {
            state = Ajax.useAjaxObject( path, param, ajax_func, html_div );
            if( count !== 1 )
            {
                alert( 'Ajax Object Use Failed ');
            }
        count++;
        }
        return state;
    }
Share Improve this question edited Aug 7, 2012 at 19:11 asked Nov 15, 2011 at 1:31 user656925user656925 1
  • Can you add more details? Like the version of IE and what code you're using? – Beanow Commented Jan 29, 2012 at 12:35
Add a ment  | 

3 Answers 3

Reset to default 3

I have this same problem, and I found a solution that works for me as long as the AJAX request is asynchronous.

The solution is to wrap the AJAX call in a setTimeout call with a delay of 0.

This seems to work 100% of the time for me.

I also verified with one of my co-workers that the 12030 error still occurs in Internet Explorer 9, as well.

<rant>So Billy G and pany see fit to provide us with the new "Metro" interface, but they can't be bothered to fix their browser that all web programmers must support</rant>

This is a documented bug with the underlying socket handling of XMLHttpRequest in internet explorer.

When you use the XMLHttpRequest object to read a response from the server, the server must have cleared the read buffer first. (even if its not interested in it).

Ensure your server side code reads the entire request bytes before sending the response.

If you specify what server technology you're using I might be able to give you an example.

You say you are looping, but perhaps setting a timeout for your retry rather than looping would be a good way to avoid the user perceiving the delay (unless you really do mean to prevent other JavaScript from executing until you get the answer!) This doesn't prevent the error, but it would be a client-side only way of mitigating the impact on the browser. (I'm assuming from your ment "as this takes up time to loop" that the browser lag. is your real problem).

Actually, I'm possibly taking you too literally... Now that I think about it an actual loop would prohibit subsequent requests too. Can you be more specific about your "looping" technique? and what you mean by "takes up time"?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745152080a4613915.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信