Activate your free membership today | Log-in

Thursday, August 20th, 2009

jXHR: XHR API, JSON-P backend conduit

Category: Ajax

The Mullet: Business up front, party in the rear

Kyle has take the XHR API that we all know and…. wrap…. and married it with a JSON-P transport to make jXHR.

He tells us more:

I’ve put out a very simple little project called jXHR which does cross-domain Ajax via JSON-P calls (meaning, totally javascript based), but does so with an emulation of the native XHR API (”onreadystatechange”, “open”, “send”, etc). It also provides some basic error handling capabilities, which is something most JSON-P solutions don’t currently offer, at least not without complicated timers, etc.

The goal was to provide a simpler interface for making cross-domain Ajax calls with JSON-P, but in nearly the same way you make same-domain calls, by using the standard XHR API. Also, I wanted the solution to be framework independent for those who don’t or can’t use jQuery, Dojo, etc

Frameworks such as Dojo allow you to choose an transport independent of their API (e.g. iframe transport versus XHR).

Posted by Dion Almaer at 6:55 am
12 Comments

++++-
4.7 rating from 20 votes

12 Comments »

Comments feed TrackBack URI

For the record, that is NOT a picture of me. :) But funny picture nonetheless, Dion. :)

Comment by shadedecho — August 20, 2009

The main point of jXHR, besides putting the familiar and well-known XHR API wrapper on top of dynamic-script-tag JSON-P calls, was to provide the “onerror” error detection handler functionality.

If you set “onerror” handler, and your JSON-P call fails for some reason, then you’ll be immediately notified, rather than needing to do your own timer detection, etc.

Also, jXHR is less than 700 bytes when minified and gzip’d, so it’s really small and easy to use just about anywhere, including bookmarklets, cross-domain widgets, etc.

Comment by shadedecho — August 20, 2009

lol funny pic

Comment by marlonbtx — August 20, 2009

so you are not using an iframe! you use script tag

Comment by marlonbtx — August 20, 2009

BTW, in honor of Dion’s awesome picture to visualize my API, this project can now be located at:

http://mullet.xhr.me

http://mulletxhr.com

Comment by shadedecho — August 20, 2009

hehe awesome

Comment by Jadet — August 20, 2009

I love mullet !

BTW, it seems that “internal_callback” variable is global…

Comment by checkca — August 20, 2009

good catch, thank you @checkca. Will fix ASAP.

Comment by shadedecho — August 20, 2009

I think this API would be interesting if its intent was to be a fallback API rather than a “similar syntax”. So if a browser supports the new standard, it uses that, but if it doesn’t, it uses JSONP, either way no manual toggling involved for the developer.

Comment by stimpy77 — August 29, 2009

@stimpy77 — i think you’ve actually hit on exactly why I think that standardizing on the same API is important… so that it’s easy to swap in optional implementations depending on technical environment but without having to code more complex code that makes calls differently. When it’s the same (or nearly the same) API, it greatly simplifies that kind of usage. And that’s my goal, to provide more options for cross-domain Ajax, but without fragmenting the API into an unmanageable mess.

Comment by shadedecho — September 16, 2009

January 1999 Motorola 328cAlthough plus size mother of the bride dressesthe first flip phone in should be sooner, but this clamshell phone is just an integrated microphonemother of bride dresses is not in the usual sense we are now referred to flip.Column Strapless Satin Tulle Wedding Dress Most of the time we are actually referring to folding clamshell handsets, but Motorola’s first cheap prom dressesclamshell phone is the famous “palm-sized” – 328c. The phone is the beginning of in the domestic market and ghetto prom dressescan be received in English and Chinese text, but it does not support sending text messages in Chinese, which is sorry. Column Satin Organdie Lace Wedding DressHowever, clear call quality and handsome appearance are popular at the time this phone place.wedding dress

Comment by wuwei — November 10, 2009

gateway W35078LD 934T2700F 934T2730F 934T2740F Replacement For Gateway P-6300 P-6301 P-6302 P-6822 P-6825gateway 2524265 6501167 6501191 Replacement For Gateway M-1600 M-1615 M-1617 M-1618 M-1618N M-1618Rgateway W35044LB 6501167 2524265 Replacement For Gateway M-6815 M-6816 M-6817 M-6821b M-6822 M-6823gateway SQU-715 6MSBG Replacement For Gateway M-1400 P-6300 T6800 T1600 M1400 M1600 series gateway SQU-720 SQU-716 W35078LD Replacement For Gateway T1410 T1412 T1616 T1620 seriesgateway SQU-715 SQU-719 SQU-721 W35052LB Replacement For Gateway M1400 M1600 M6800 T1600 T6800 seriesgateway W35044LB W35044LB-SP W35044LB-SY 3UR18650F-2-ARM Replacement For Gateway M-150 M-1400 M-1600 M-6800 P-6300 T6800 T1600 M1400 M1600 seriesgateway W35078LD 934T2700F 934T2730F 934T2740F batterygateway 2524265 6501167 6501191 batterygateway W35044LB 6501167 2524265 batterygateway SQU-715 6MSBG batterygateway SQU-720 SQU-716 W35078LD batterygateway SQU-715 SQU-719 SQU-721 W35052LB batterygateway W35044LB W35044LB-SP W35044LB-SY 3UR18650F-2-ARM battery

Comment by cheapbattereis — January 6, 2010

Leave a comment

You must be logged in to post a comment.