由于某些原因,该函数与firefox一起冻结,直到它从请求的站点完全检索流。有没有防止冻结的机制,这样它就可以按预期工作了?
在XUL中
<statusbarpanel id="eee_label" tooltip="eee_tooltip"
onclick="eee.retrieve_rate(event);"/>Javascript
retrieve_rate: function(e)
{
var ajax = null;
ajax = new XMLHttpRequest();
ajax.open('GET', 'http://site.com', false);
ajax.onload = function()
{
if (ajax.status == 200)
{
var regexp = /blabla/g;
var match = regexp.exec(ajax.responseText);
while (match != null)
{
window.dump('Currency: ' + match[1] + ', Rate: '
+ match[2] + ', Change: ' + match[3] + "\n");
if(match[1] == "USD")
rate_USD = sprintf("%s:%s", match[1], match[2]);
if(match[1] == "EUR")
rate_EUR = sprintf("%s:%s", match[1], match[2]);
if(match[1] == "RUB")
rate_RUB = sprintf("%s/%s", match[1], match[2]);
match = regexp.exec(ajax.responseText);
}
var rate = document.getElementById('eee_label');
rate.label = rate_USD + " " + rate_EUR + " " + rate_RUB;
}
else
{
}
};
ajax.send();我试图将window.dump()放在ajax.send()之后,但它也在请求完成后被转储到控制台中。
发布于 2010-04-29 22:14:04
您需要通过将true作为最后一个参数传递给ajax.open来发出异步AJAX请求。
请注意,完成此操作后,send函数将立即返回,之后的任何代码都将在请求完成之前运行。
https://stackoverflow.com/questions/2737995
复制相似问题