Dojo Goodness, Part 4 (Easy AJAX)

by Matthew Russell

This week's installment of Dojo Goodness demonstrates dojo.xhrGet, an easy way to sprinkle some AJAX into your application and one of the biggest staples in Dojo. (In case the "xhr" part of that API call is a curve ball, it simply refers to the XMLHttpRequest object.) The xhrGet function streamlines the work entailed in issuing a GET request to the server, is included in Base, and is intuitive to use in that you pass it some descriptive keyword arguments; the default behavior is to issue an asynchronous request.

4 Comments

Andrew Kutz
2008-03-27 14:23:16
Matthew,


Great series! I do have a question that upon Googling it is clear there is no clear decision. My question goes to the "Like to see in an upcoming column." I am writing an application with GWT and was turned onto Dojo because it apparently is developed with 508 compatibility in mind. What are your thoughts on GWT vs Dojo, and more in general, what design practices (graceful degradation for example -- although I would argue that GD isn't really about degrading an application but rather providing an entirely separate one) one uses to develop 508 accessible code with Dojo (or GWT for that matter if you happen to know)?

wxj
2008-07-29 01:01:10
wenxian
vlad_dojo
2008-08-09 16:36:45
Hi, I ordered your book. I am very impressed with the Dojo kit,
using it to program my system's end-user frondend. Then plan to use the upcoming dojo 1.2 to program the configuration editor using AdobeAir and Dojo.


I have had quite a bit of difficulties finding out how JSONP
works (since I need to load cross-domain data).
I had to look through the source code of the
dojo/rpc/JsonpService


and the only function I could use there to make a call
was bind. And with that function apparently underneath
the GET method is used, and I still do not know how to use
the POST method for JSonp.


Another thing, I could not find a good explanation
how the 'deferred' argument is to be used
when calling dojo.rpc.JsonpService
Because for JsonP one already has to specify the callback
function as a parameter:


var srvc=new
dojo.rpc.JsonpService(
{url:"this one does not matter",
callbackParamName:"my_callback",
timeout: "3000"
}
);



And then the deferred argument that is passed
to the bind call does not appear to be used....


This area is confusing (I read that
the upcoming version 1.2 will have more cross-domain
communications support, but this will be some time
before 1.2 gets out there on the CDN sites, and your book
will probably not talk about it (since it is still work
in progress).


Another area of difficulty is figuring out how to use
DOJO's base APIs to 'improve' the robustness of my own
java script
code -- using dojo's Function binding, Modularization and
other facilities and conventions.


In other words, Dojo kit is well written but it would be
nice to understand design patterns, conventions/etc that
were used to achieve such a high-level of robustness and
complexity.
In order to use the same methods for our own development


ptwobrussell
2008-08-09 17:50:58
@vlad_dojo: Hey - I do cover jsonp somewhat extensively in the book as do I provide extensively coverage of Deferreds and how they are used and propagated in the I/O subsystem, and virtually all of Base and Core.


I can totally empathize with you on having to grok source code. It's not fun and far from ideal -- in fact, that's a huge reason why I wrote the book. I really do think my book will help you in these areas. I tried really hard to elaborate on patterns and generalities across the broader parts of the toolkit without sacrificing details on the nitty gritty.


Could you do me a favor and post something back once you receive the book and have a chance to determine how well it did/didn't meet your needs?