Login   Register  
Icontem

Cross-Domain AJAX versus JSONP - CDA Cross Domain AJAX package blog

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  All package blogs All package blogs   CDA Cross Domain AJAX CDA Cross Domain AJAX   Blog CDA Cross Domain AJAX package blog   RSS 1.0 feed RSS 2.0 feed   Blog Cross-Domain AJAX ver...  
  Post a comment Post a comment   See comments See comments (2)   Trackbacks (0)  

Author: Hensel Hartmann

Posted on:

Package: CDA Cross Domain AJAX

Cross-Domain AJAX is an alternative approach to send AJAX requests to a Web server and process the retrieved response.

Read this article learn about Cross-Domain AJAX and its main advantages when compared to JSONP.




Contents

Introduction to Cross-Domain AJAX

Cross-Domain AJAX advantages over JSONP

Conclusions


Introduction to Cross-Domain AJAX

Whenever I need to load JavaScript application components from the Web server, I usually insert a JavaScript tag in the Web page document and used some "dirty" tricks to execute it.

Cross-Domain AJAX uses this approach to implement a cleaner solution wrapped as a jQuery plug-in.

Cross-Domain AJAX advantages over JSONP

1. JSONP requires that the server responds with JSON data

JSONP requires that the server returns JSON data wrapped around a padding function to process that data.

Therefore you need to provide the function on the browser side that still needs to process the JSON data to do something useful with it.

Cross-Domain AJAX does not need any JavaScript code to be previously loaded on the browser to process the server response. The JavaScript code that is loaded simply executes by itself, so all the application logic is delivered from the server.

For example, you can start displaying of syndicated videos. If you were searching for content, JSONP cannot do more by itself then delivering the search results, but not retrieve and execute application that actually processes the results.

With Cross-Domain AJAX, loading a complete application, and even additional plugins later, it is not an issue.

In my work with embedded applications, I often need user or site licenses to be verified before loading and executing the application code. Sometimes I need plugins to be loaded on demand. JSONP is not very helpful for these purposes.

2. JSONP provides no error handling in case of failure

If for some reason a JSONP fails to respond as expected, there is no way to handle the errors gracefully. With Cross-Domain AJAX, that is not an issue.

Cross-Domain AJAX was developed in such way that it is able to verify whether the server response was returned without error before proceeding and executing the returned application code.

If you expect that the response may fail to be returned by the server, you can even set a timeout value, after which you may retry and call the server again. This is easily accomplished by the waiter helper.

Conclusions

This article presents the way I understand the differences between the way JSONP and Cross-Domain AJAX are supposed to work, but I confess that I have not worked much with JSONP, so I admit may be wrong on some aspects.

I rarely need just JSON data. In my applications I mainly need extensions to be loaded dynamically on demand.

My intention with Cross-Domain AJAX was to eliminate the use of iframes from applications like this one. Here all the embedded script does initially is to call an iframe to show the AJAX application. JSONP did not help me on that purpose. With Cross-Domain AJAX, getting rid of the iframes, it is not an issue.

As a final note, I would like to mention that I was based on some information from this article.

The Cross-Domain AJAX plugin can be obtained here in this site.

You need to be a registered user or login to post a comment

Login Immediately with your account on:

Facebook ConnectGmail or other Google Account
Hotmail or Microsoft Windows LiveStackOverflow
GitHubYahoo


Comments:

2. Cross-Domain AJAX plugin = JSONP + External Proxy YQL - Daniel Ortiz Esquivel (2012-08-09 09:37)
Cross-Domain AJAX plugin = JSONP + External Proxy YQL... - 0 replies
Read the whole comment and replies

1. nice - peter fimson (2012-08-08 16:59)
liked it... - 0 replies
Read the whole comment and replies




  Post a comment Post a comment   See comments See comments (2)   Trackbacks (0)  
  All package blogs All package blogs   CDA Cross Domain AJAX CDA Cross Domain AJAX   Blog CDA Cross Domain AJAX package blog   RSS 1.0 feed RSS 2.0 feed   Blog Cross-Domain AJAX ver...