Nov 17 2009

goog.net.XhrIo: make simple ajax calls with Google Closure

Category: google closureDavide Zanotti @ 8:10 am

Closure has a consistent package called goog.net, which contains a lot of classes to work with ajax and remote http requests. In this post I want to show how to create a basic xhr object to make get/post calls, listen for related ajax events and send data to server. Once imported the main js file (base.js), we will require the following:

1
2
3
4
goog.require("goog.dom");
goog.require("goog.net.XhrIo");
goog.require("goog.structs.Map");
goog.require("goog.Uri.QueryData");

The most important import is goog.net.XhrIo, which represents the object wrapping the XmlHttpRequest and allows us to retrieve and send information to/from the server. This class is a pretty low level api, which means that several tasks are not as simple and automatic as they would in jQuery or such libraries, but on the other hand this offers us more control and consciousness of what we are going to do.
The first step is instantiate an object of type goog.net.XhrIo and take a reference to it:

Continue reading “goog.net.XhrIo: make simple ajax calls with Google Closure”

Tags: , ,


May 29 2009

Jetpack: building Firefox plugin with Javascript (and jQuery)

Category: browsers,javascriptDavide Zanotti @ 8:08 am

I discovered a couple of days ago a new open source project from Mozilla labs: Jetpack.
It’s an “API set” which allows to build Firefox’s plugins by using Javascript, HTML (including new HTML 5 tags: “video” and “audio“) and CSS (oh yes, in a single word Ajax).
Jetpack is still in an early development phase and released as 0.1 version.
Here you can find the (really brief) api documentation and here some examples.
I would like to try it in the future

Tags: , , , ,


Nov 10 2008

Handle multiple ajax calls in a fixed incremental order

Category: ajaxDavide Zanotti @ 4:11 pm

In a project which I’m working on, I’ve realized a Javascript object (I’ve called it MediaBrowser), which displays images and flv videos into a box (a dynamic div rendered at runtime). The data used by this object is contained into multiple XML files, which are loaded by ajax (potentially it can loads infinite files passed as array of urls). The problem was: ajax is by definition asynchronous, so each time I load the page with my cool MediaBrowser, the order in which the objects (images and videos) are processed and displayed varies based on the order in which responses to the ajax calls are returned. IE: if I call file_1.xml, file_2.xml and file_3.xml, which contain respectively:

Continue reading “Handle multiple ajax calls in a fixed incremental order”

Tags: , ,