2

I'm working on a Firefox plugin which will both retrieve and send data to a http-server, but I'm having some issues as to how to do this. The plugin will detect the current url the user's on and automatically fetch data (comments, score, etc) that's related to that page from an http-server (which in turn fetches them from a MySQL server). The plugin also has text-fields where the user can submit their own comments and rate the current site.

So far, I've only coded the layout and behavior (JavaScript) of the plugin. The server hasn't been implemented yet.

Some of the user input needs to be evaluated through a server before being inserted into the database. So the client needs to connect to this http-server for sending data as well.

I've searched online and found a few examples, but none of them seem similar enough to what I'm trying to do. Being the first time I'm trying to do this, I'm unsure of how to approach this.

I guess my first question is if there are any common techniques for doing this for Firefox plugins? If not, is AJAX and jQuery a feasible approach? I read something about Socket.io and Node.js, what about those?

I'm not looking for code, but rather guidance and advice of how to do this. This is the first time I take on a project like this, and if there is any detail I've missed out in this post, let me know.

Chris
  • 57,622
  • 19
  • 111
  • 137

1 Answers1

5

As you don't provide much information of the specifics of the code, I don't know if you are talking about a content script or if you have a panel.

In any case, you can use AJAX to communicate with the server (with or without jQuery). It's the easiest way to do it.

About using web sockets, it has been asked on SO before: Why use AJAX when WebSockets is available?. Do you need a bi-directional, full-duplex and long-running connection between a browser and server? If the answer is no, then go for AJAX.

Community
  • 1
  • 1
dgil
  • 2,318
  • 2
  • 23
  • 39
  • Thanks for your answer! The plugin is a panel. The connection needs to be bi-directional not long-running, and not necessarily full-duplex. I'm guessing I'll go for AJAX. Would you know any tutorial or helpful page for this? Most things I've found involve php or xmlhttprequest, which I don't think I need here. Suggestions? – Chris Apr 23 '15 at 10:55
  • You have some examples in the Firefox Addon SDK of `Request`, a simplified version of XHR. Check it out https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/request – dgil Apr 23 '15 at 11:13