开发者

Firefox extension is freezing Firefox until request is completed

For some reason the function is freezing along with firefox until it fully retrieve the stream from requested site. Is there any mechanism to prevent freezing, so it works as expected?

in 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();

I tried to put window.dump() right after ajax.send() and it dumped in the console also after the request is completed.


You need to make an asynchronous AJAX request by passing true as the last parameter to ajax.open.

Note that once you do that, the send function will return immediately, and any code after it will run before the request finishes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜