" XMLHtt prequest异常101 QUOT;在嵌套的AJAX查询 [英] "XMLHttpRequest Exception 101" on nested AJAX queries

查看:104
本文介绍了" XMLHtt prequest异常101 QUOT;在嵌套的AJAX查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个AJAX获取一个二进制文件我解析在JavaScript中。 (雷神之锤2的BSP,如果有人问津。)在code,以获取和分析工作正常的初始文件,看起来大致是这样的:

I'm doing an AJAX fetch of a binary file the I am parsing in javascript. (Quake 2 BSPs, if anyone cares.) The code to fetch and parse the initial file is working fine, and looks roughly like this:

function loadFile(url) {
    var request = new XMLHttpRequest();

    request.onreadystatechange = function () {
        if (request.readyState == 4 && request.status == 200) {
            var parsed = parseFile(request.responseText);
        }
    };

    request.open('GET', url, true);
    request.overrideMimeType('text/plain; charset=x-user-defined');
    request.setRequestHeader('Content-Type', 'text/plain');
    request.send(null);
}

正如我所说的,工作正常,一切都加载和正确分析。但是,该文件还描述了一些辅助文件(纹理)需要进行检索,以及,所以我补充说,应该加载和分析所有这些文件中,像这样的内部循环:

As I said, that works fine, and everything loads and parses correctly. However, the file also describes several secondary files (textures) that need to be retrieved as well, and so I've added an inner loop that should load and parse all of those files, like so:

function loadFile(url) {
    var request = new XMLHttpRequest();

    request.onreadystatechange = function () {
        if (request.readyState == 4 && request.status == 200) {
            var parsed = parseFile(request.responseText);
            for(var i = 0; i < parsed.files.length; ++i) {
                loadSecondaryFile(parsed.files[i].url); // Request code here is identical to this function
            }
        }
    };

    request.open('GET', url, true);
    request.overrideMimeType('text/plain; charset=x-user-defined');
    request.setRequestHeader('Content-Type', 'text/plain');
    request.send(null);
}

function loadSecondaryFile(url) {
    var request = new XMLHttpRequest();

    request.onreadystatechange = function () {
        if (request.readyState == 4 && request.status == 200) {
            var parsed = parseSecondaryFile(request.responseText);
        }
    };

    request.open('GET', url, true);
    request.overrideMimeType('text/plain; charset=x-user-defined');
    request.setRequestHeader('Content-Type', 'text/plain');
    request.send(null);
}

不过,从环路内进行的每个请求立即失败的消息(在Chrome,开发频道): NETWORK_ERR:XMLHtt prequest异常101 这令我奇怪的,因为如果我叫 loadSecondaryFile 的loadFile 之外它完美的作品。

But every request made from within that loop immediately fails with the message (in Chrome, Dev Channel): NETWORK_ERR: XMLHttpRequest Exception 101 This strikes me as strange, since if I call loadSecondaryFile outside of loadFile it works perfectly.

我最初的即时通讯pression是发起于 onreadystatechage 的另一个一类One Ajax调用可能是坏朱朱,但包裹在二级Ajax调用的SetTimer 并没有任何区别。

My initial impression was that initiating an one ajax call in the onreadystatechage of another may be bad juju, but wrapping the secondary ajax calls in a setTimer doesn't make any difference.

任何想法?

推荐答案

和......成功了!所以,我觉得自己很愚蠢,我现在没有办法任何人可以给我,我presented信息的解决方案实现。非常抱歉!

And... SUCCESS! So I feel really stupid, and I realize now that there's no way anyone else could have given me a solution with the information I presented. Terribly sorry!

它无关,与AJAX和一切与我是如何得到我的网址。回想一下,我提到我是从一个Quake2中BSP的加载的二进制数据,在这种情况下,纹理路径。在BSP格式的纹理被存储为固定长度的32位串用null填充。我用SUBSTR像这样读取它们:

It has nothing to do with AJAX and everything to do with how I was getting my URLs. Recall that I mentioned I was loading binary data from a Quake2 bsp, in this case, texture paths. Textures in the bsp format are stored as fixed length 32 bit strings with null padding. I was reading them using substr like so:

VAR路径= fileBuffer.substr(fileOffset,32);

我以为是给我像e2u3 /短片一个字符串,但实际上是给我e2u3 /夹\ 0 \ 0 \ 0 \ 0 ...当然,打印时,这会看起来是正确的(因为重新console.log的presents空字符如无物。),但浏览器立刻认识到这是一个糟糕的URL,并把它扔出去。

Which I thought was giving me a string like "e2u3/clip", but in reality was giving me "e2u3/clip\0\0\0\0..." Of course, when printed this would look correct (since console.log represents the null char as nothing.) but the browser recognized it immediately as a bad URL and tossed it out.

更改我读code到:

VAR路径= fileBuffer.substr(fileOffset,32).replace(/ \ 0 + $ /,'');

让我有效字符串,并修复了我所有的视AJAX的问题! 叹息

Gives me valid strings and fixes all of my apparent AJAX problems! sigh

感谢所有的建议!它帮助把我在正确的轨道。

Thanks for all the suggestions! It helped put me on the right track.

这篇关于&QUOT; XMLHtt prequest异常101 QUOT;在嵌套的AJAX查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆