MozillaZine

XMLHttpRequest used in XPCOM - problem

Talk about add-ons and extension development.
gemme
 
Posts: 25
Joined: May 13th, 2006, 1:44 pm
Location: Poland

Post Posted June 12th, 2006, 6:20 am

Hello

I want to download some data in my XPCOM component. I made this code:
Code: Select all
for (var el in this.ObservedSites)
{
   var Request =
      Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
      .createInstance(Components.interfaces.nsIXMLHttpRequest);
   
   Request.open("GET", this.ObservedSites[el].URL, true);
   Request.el = el;
   Request.onload = this.siteChecked;
   Request.send(null);
}

I set Request.el to identify responses (as in http://kb.mozillazine.org/XMLHttpReques ... nous_calls - adding custom data to XMLHttpRequest object).

But I've got this error:
Cannot modify properties of a WrappedNative = NS_ERROR_XPC_CANT_MODIFY_PROP_ON_WN
on the line:
Code: Select all
Request.el = el;

Is there any way to make this asynchronous and to identify (in the onload event) requests?
active & creative | polish homepage | monitor web pages

doron
 
Posts: 935
Joined: November 4th, 2002, 4:50 pm

Post Posted June 12th, 2006, 7:14 am

var myThis = this;
var func = function(){myThis.siteChecked('unique identifier')};
Request.onload = func;
If you see a marquee, clap your hands!

gemme
 
Posts: 25
Joined: May 13th, 2006, 1:44 pm
Location: Poland

Post Posted June 13th, 2006, 10:23 am

The line
Code: Select all
Request.onload = func;
still causes the "Cannot modify properties of a WrappedNative = NS_ERROR_XPC_CANT_MODIFY_PROP_ON_WN" error :(

EDIT: Adding
Code: Select all
Request instanceof Components.interfaces.nsIJSXMLHttpRequest;
helped.

This thread was helpful: http://www.mail-archive.com/dev-tech-xp ... 00264.html
active & creative | polish homepage | monitor web pages

gemme
 
Posts: 25
Joined: May 13th, 2006, 1:44 pm
Location: Poland

Post Posted June 15th, 2006, 7:30 am

Argh, it still doesn't work correctly.

The code is
Code: Select all
for (var el in this.ObservedSites)
{
   (...)
   var Notify = this;
   var func =
      function(event)
      {
         Notify.siteChecked(event, el);
      };
   Request.onload = func;
   (...)
}


But when there are 2 items in this.ObservedSites, Notify.siteChecked is called twice, with the same el value.
I don't understand it ...
active & creative | polish homepage | monitor web pages

gemme
 
Posts: 25
Joined: May 13th, 2006, 1:44 pm
Location: Poland

Post Posted June 17th, 2006, 6:57 am

This code hopefully works, if it can help anyone in the future:
Code: Select all
var Notify = this;
var func =
   eval(
      "function(event) \
      { \
         Notify.siteChecked(event, " + el + "); \
      };"
      );
Request.onload = func;
active & creative | polish homepage | monitor web pages

ashishpatil
 
Posts: 31
Joined: March 24th, 2009, 6:18 am

Post Posted May 12th, 2009, 10:16 pm

Hey you forgot your code and use this one.

function(url, callback)
{
var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1']
.getService(Components.interfaces.nsIXMLHttpRequest);

var this_ = this;

if (callback)
{
request = request.QueryInterface(Components.interfaces.nsIDOMEventTarget);
request.callback = callback;
request.addEventListener("load",
function (event) {
this_.SendAsyncDone(event);
},
true);
}
try {
request.open("GET", url, true);
request.setRequestHeader("User-Agent" , userAgent);
request.send(null);
}
catch(e)
{

}
},

asyncDone: function(event)
{
var request = event.target;

if (request.readyState != 4)
return;

var callback = request.callback;
callback(request.responseText);
if (request.status == 200)
request.done = true;
}
its woking fine for me, let me know if you helped with it.

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest