Make Cross-Domain AJAX Requests with xdRequest
xdRequest is an open-source JavaScript library that I’ve developed for making cross-domain AJAX requests. In this day and age, with web browsers becoming very fast and powerful, it has become quite possible to build web applications with much of the work performed by the client. xdRequest makes it possible to easily pull data from other sources and manipulate it all on the client-side. With xdRequest, you will no longer need to perform data extractions/manipulations from other sources on a server. It can all happen right in the browser.
I had recently been fooling around quite a bit with YQL, which does provide some built-in features to make cross-domain http requests. It can be done with the html open data table. You can try it out from the YQL Console. Just go to the data tables section on the right side and select Data > html. Unfortunately, the built-in html table is somewhat limited. You can only make requests using the GET method, and it does not provide any mechanism for sending/receiving HTTP headers.
Someone in the YQL forums posted a YQL feature request to add POST and other HTTP request methods to the html table. Someone responded with the suggestion of building an open data table to do just that. I then started reading the open data table documentation, and came to realize that what you can do with YQL and open data tables is nothing short of astounding. You can use server-side JavaScript to request data from multiple sources and manipulate it in any way you see fit.
I started developing my own custom open data table for the particular project I was working on at the time, and eventually the project morphed into xdRequest. Because I needed to track cookies and redirects in my little project, I realized that it would be great to develop a generic library that could handle such requests. Eventually, I more or less abandoned the previous project to develop xdRequest. Here are some of the features, as highlighted on the project page:
- Make cross-domain requests using the GET and POST methods
- Add request headers along with the requests
- Automatically collect cookies sent by the remote web server
- Automatically follow redirects and collect cookies along the way
- Properly store/transmit cookies, much like the popular server-side library, cURL
- Automatically submits hidden fields detected within forms on webpages
I also put together a relatively simple xdRequest demo. It brings in data from espn.go.com. When the page loads, it makes an xdRequest to ESPN for the University of Florida Football schedule. I’m a die-hard Gator and UF alumnus, so that’s why I decided to start the demo with the UF football schedule. When you can click the hyperlinks in the demo, xdRequests are made to ESPN to load schedules for other teams, as well as the box scores for games. It’s a simple example, but the sky is the limit as to what you can do with xdRequest.
If you’re interested in learning more about the project, be sure to check out the xdRequest project page. If you’re a JavaScript geek and would like to join, just drop me a line and I’ll gladly add you to the project. I’m kind of a n00b when it comes to object-oriented programming with JavaScript, so I could definitely use some help to clean up the code, make enhancements, find bugs, and fix bugs. This is the first “official” Open Source project I’ve ever worked on, so I’m a n00b when it comes to working on OSS as well.
If you like xdRequest and build any cool web applications with it, let me know and I’ll link to it from the project page. If you have any feature suggestions or encounter any bugs, please report them in the xdRequest issue tracker.
Related Posts
- Keep Track of New Television Show Episodes with RerunCheck
- WordPress PageRank Widget Plugin
- T-Mobile to Bring first Android Phone to Market
Related Websites
- Ultimate Frugality - The Best Free Software For Macs.
- Review of the Garmin Forerunner 310 XT
- Data Hiding in C: Programming Using Incomplete and Derived Types
Comments
-
Davide Zanotti
-
GeekLad
-
Kevin Gigiano
-
GeekLad
-
Kevin Gigiano
-
GeekLad
-
David Hopkins
-
David Hopkins
-
GeekLad
-
David Hopkins
-
GeekLad
-
David Hopkins
-
Paul
-
GeekLad
-
Paul
-
GeekLad
