Ropardo Sowftware development company

Experience software development with ROPARDO S.R.L.

RSS Feed
RSS Feed
  • Home
  • About ROPARDO S.R.L
  • Our websites

Cross-domain AJAX calls

In these days all web2.0 apps make use of AJAX to save bandwidth, user time or to display data without refreshing the page. When you make an AJAX request the response could be plain text, Html or JSON, but if you want to make a cross-domain AJAX call you can’t because the browser security model dictates that XMLHttpRequest must have the same domain in order to communicate. This is where you need to use JSONP, this technique will make the AJAX call and after will inject the response in a script tag and will pass the data to a specified function.

Some JavaScript Libraries help you dealing with JSONP and in this article I will show you how to make cross-domain AJAX calls with MooTools and jQuery.

MooTools

If you want to make JSONP requests you need the plugin Request.JSONP from MooTools More.

var myRequest = new Request.JSONP({
	url: 'http://twitter.com/statuses/user_timeline/twitter.json',
	onComplete: function(data) {
		//do something with data
	}
}).send();

MooTools will automatically add callback parameter with function which will handle the response, but if the server requires another parameter for callback you can add the callBackKey option. If you need to pass data to request you need to add the values in data option.

var myRequest = new Request.JSONP({
	url: 'http://domain.com/getData',
	callBackKey: 'callback',
	data: {
		someData: 'someValue'
	},
	onComplete: function(data) {
		//do something with data
	}
}).send();

jQuery

If you worked before with $.ajax there are no big difference between a request for HTML/JSON and JSONP calls, you need just to change dataType to jsonp and to specify the callback parameter in jsonp option.

$.ajax({
	url: 'http://twitter.com/statuses/user_timeline/twitter.json&callback=?',
	dataType: 'jsonp',
	jsonp: 'callback',
	success: function(data){
		//do something with data
	}
});

You can read more about JSONP here.

Tags: ajax javascript jQuery jsonp mootools

 Posted in: Javascrip/AJAX
September 23, 2009 | Andrei Igna | 7 Comments

7 Responses

  • Christian Louboutin Shoes
    June 9, 2010
    1

    Nice article, nice blog, I have

    bookmarked your blog, it is worthy doing this. Thank you.

  • registry cleaner
    June 15, 2010
    2

    Nice post…Thank you for sharing some good things!!

  • Cheap Insurance Quotes
    June 16, 2010
    3

    It’s a nice blog,I like it

  • bad credit loan
    July 29, 2010
    4

    Enjoyed reading

    the report – most informative thanks

  • best registry cleaner
    July 30, 2010
    5

    good share, great article, very usefull for us…thanks!

  • best registry cleaner
    July 31, 2010
    6

    Good article Thank you so much

  • SRW
    December 6, 2010
    7

    Keep up the great work!I like blog.ropardo.ro !


  • « Previous post
  • Next post »
  • Recent Posts

    • How to put online the Apache 2.4 Server
    • Exit from an Android application
    • Showing keyboard automatically in Android dialogs
    • Request Elevated Privileges in Windows Vista and 7 where UAC is enabled
    • Checkboxes unchecked value
  • Ropardo is Hiring

  • Subscribe

    • Add to Google Reader or Homepage Add to netvibes TopOfBlogs
  • Recent Comments

    • Laurent on GWT 2.1 – Uploading a file using the RPC mechanism
    • ketone review on GWT/GXT – File Upload
    • Seris on Multiple select ComboBox in RadGrid filter
    • Mihai Ionescu on Basic file encryption with PHP mcrypt using cryptastic class
    • Furqon on Basic file encryption with PHP mcrypt using cryptastic class
  • Archives

    • September 2012 (1)
    • August 2012 (2)
    • June 2012 (1)
    • March 2012 (1)
    • February 2012 (1)
    • November 2011 (1)
    • September 2011 (4)
    • July 2011 (3)
    • June 2011 (2)
    • May 2011 (4)
    • April 2011 (4)
    • March 2011 (3)
    • February 2011 (2)
    • January 2011 (2)
    • December 2010 (1)
    • November 2010 (4)
    • October 2010 (4)
    • August 2010 (3)
    • July 2010 (3)
    • June 2010 (6)
    • May 2010 (8)
    • April 2010 (7)
    • March 2010 (9)
    • February 2010 (6)
    • January 2010 (5)
    • December 2009 (7)
    • November 2009 (9)
    • October 2009 (10)
    • September 2009 (14)
    • August 2009 (10)
    • July 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (1)
    • March 2009 (1)
    • October 2008 (3)
    • October 2007 (3)
    • July 2007 (4)
    • June 2007 (1)
    • May 2007 (3)
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Categories

    • News (16)
    • Ropardo Team (8)
    • Ropardo Products (6)
      • File Tracking Client (4)
      • iManagement (2)
    • Software Development (86)
      • Microsoft.NET (23)
      • Java (43)
      • Oracle (8)
      • Power Builder (3)
      • Liferay (5)
      • Lotus Notes (9)
      • xWiki (4)
    • System Adminstration (13)
      • Linux (10)
      • Windows (3)
    • Programming (4)
    • Uncategorized (3)
    • Databases (10)
      • MSSQL (5)
      • PostgreeSQL (3)
    • Microsoft.NET (2)
    • Web Development (30)
      • ASP/ASPX (3)
      • Content Management Systems (1)
      • HTML/CSS (6)
      • Javascrip/AJAX (8)
      • PHP (8)
    • Oracle E Business Suite (6)
  • Tags

    .NET ajax blog C# certification client CMS control css database Debugging django Domino Eclipse extension file tracking filter fun gentoo google Hibernate how to html image iManagement import Java javascript jQuery liferay Linux Lotus Notes lotus script Oracle Oracle BI Publisher 11g PHP portal PostgreSQL powerbuilder Python SQL Telerik velocity xml Xwiki

© 2013 ROPARDO s.r.l..

Powered by WordPress. Styled by Ropardo