使用相同 URLRequest 时的 URLLoader.load() 问题

发布于 2024-09-04 18:39:12 字数 1066 浏览 8 评论 0原文

我的 URLLoader 事件监听器有问题,但此问题发生在 IE 中,而不是 FF 中。

public function getUploadURL():void {   
    var request:URLRequest = new URLRequest();
    request.url = getPath();
    request.method = URLRequestMethod.GET;

    _loader = new URLLoader();
    _loader.dataFormat = URLLoaderDataFormat.TEXT;
    _loader.addEventListener(Event.COMPLETE, getBaseURL);

    _loader.load(request);
}

private function getBaseURL(event:Event):void {
    _loader.removeEventListener(Event.COMPLETE, getBaseURL);
}

问题是我的 getBaseURL 在我执行代码至少一次后会自动执行,但只有在 IE 中才会出现这种情况。发生的情况是我调用 getUploadURL,我确保服务器发送一个将导致 Event.COMPLETE 的事件,因此 getBaseURL 被执行,并且侦听器被删除。如果我调用 getUploadURL 方法并输入错误的路径,我不会得到 Event.COMPLETE,而是得到一些其他事件,并且 getBaseURL 不应被执行。

这是 FireFox 中的正确行为。在IE中,看起来load()方法实际上并没有调用服务器,它直接跳转到Event.COMPLETE的getBaseURL()。在分配新的 URLLoader 之前,我检查了 _loader 上的 willTrigger() 和 hasEventListener(),结果发现该事件已被很好地删除。

我希望我说得通,我简化了我的代码。快速总结一下:在 FireFox 中它运行良好,但在 IE 中,第一次调用可以工作,但第二次调用不会真正调用 .load() 方法;它似乎使用了第一次调用之前存储的结果。

我希望有人能帮助我, 谢谢你,

鲁迪

I have an issue with my eventListeners with the URLLoader, but this issue happens in IE, not in FF.

public function getUploadURL():void {   
    var request:URLRequest = new URLRequest();
    request.url = getPath();
    request.method = URLRequestMethod.GET;

    _loader = new URLLoader();
    _loader.dataFormat = URLLoaderDataFormat.TEXT;
    _loader.addEventListener(Event.COMPLETE, getBaseURL);

    _loader.load(request);
}

private function getBaseURL(event:Event):void {
    _loader.removeEventListener(Event.COMPLETE, getBaseURL);
}

The issue is that my getBaseURL gets executed automatically after I have executed the code at least once, but that is the case only in IE. What happens is I call my getUploadURL, I make sure the server sends an event that will result in an Event.COMPLETE, so the getBaseURL gets executed, and the listener is removed. If I call the getUploadURL method and put the wrong path, I do not get an Event.COMPLETE but some other event, and getBaseURL should not be executed.

That is the correct behavior in FireFox. In IE, it looks like the load() method does not actually call the server, it jumps directly to the getBaseURL() for the Event.COMPLETE. I checked the willTrigger() and hasEventListener() on _loader before assigning the new URLLoader, and it turns out the event has been well removed.

I hope I make sense, I simplified my code. To sum up quickly: in FireFox it works well, but in IE, the first call will work but the second call won't really call the .load() method; it seems it uses the previously stored result from the first call.

I hope someone can please help me,
Thank you,

Rudy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如日中天 2024-09-11 18:39:12

尝试向 url 添加随机变量以防止缓存。

var url:String = getPath();
//if path already contains some variables, replace ? with &
url += "?random=" + Math.random(); 
request.url = getPath();

Try adding a random variable to the url to prevent caching.

var url:String = getPath();
//if path already contains some variables, replace ? with &
url += "?random=" + Math.random(); 
request.url = getPath();
童话里做英雄 2024-09-11 18:39:12

可能该请求已被缓存。

var hdr:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
....
request.requestHeaders.push(hdr);

Possibly the request has been cached.

var hdr:URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
....
request.requestHeaders.push(hdr);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文