Reading from a http-get presenting in Firefox bookmarks


I'm trying to get a Firefox plugin to read data from a HTTP get, parse the results and present them as links in a bookmark-like drop-down menu.

My quesion then is: Does anyone have any sample code that will do this?

By : Tnilsson


Having never developed one myself, I'm not certain how this is typically done in Firefox plugins, but since plugin scripting is JavaScript, I can probably help out with the loading part. Assuming a variable named url containing the URL you want to request:

var xmlhttp = new XMLHttpRequest();"GET", url, true);

xmlhttp.onreadystatechange = function() {
    if(this.readyState == 4) { // Done loading?
        if(this.status == 200) { // Everything okay?
            // read content from this.responseXML or this.responseText
        } else { // Error occurred; handle it
            alert("Error " + this.status + ":\n" + this.statusText);


A couple of notes on this code:

  • You may want more sophisticated status code handling. For example, 200 is not the only non-error status code. Details on status codes can be found here.
  • You probably want to have a timeout to handle the case where, for some reason, you don't get to readyState 4 in a reasonable amount of time.
  • You may want to do things when earlier readyStates are received. This page documents the readyState codes, along with other properties and methods on the XMLHttpRequest object which you may find useful.

Robert Walker did a great job of describing how to send the request. You can read more about Mozilla's xmlhttprequest here.

I would just add that the response would be found (using Robert's code) using


(Edit - i didn't read closely enough, thanks Robert)

You didn't indicate exactly what the data was, although you mentioned wanting to parse links from the data. You could the xmlhttp.responseText as an xml document, parse out the links, and place it into a menulist or whatever you like.

Phil, different parts of the application call each other using WCF. By "return exceptions serialized as XML," I meant that the return value of the function wold be an exception object. Success would be indicated by null.

I don't think that's the right option.

WCF fault contracts sound good, but I don't know anything about them. Checking google right now.

By : brien

This video can help you solving your question :)
By: admin