Access cross-domain data with AJAX using JSONP, JQuery

My JQuery skills are a bit non existent so you can expect quite a bit of stuff about it.  I’ve run into the

XMLHttpRequest cannot load  …. not allowed by Access-Control-Allow-Origin.

I do have my NodeJS server returning JSONP data but didn’t really know how I am suppose to call it from JQuery.

Used the two links below and came up

$.ajax({
  dataType: 'jsonp',
  jsonp: 'callback',
  url: 'API url?callback=?',
  success: function (data) {
    callback(data)
  },
});

The data that comes back will already come back as JSON Object data so no need to do a JSON.parse.

References:

http://www.fbloggs.com/2010/07/09/how-to-access-cross-domain-data-with-ajax-using-jsonp-jquery-and-php/

http://stackoverflow.com/questions/2366909/problem-with-jquery-and-ajax-when-trying-to-parse-jsonp

Advertisements
This entry was posted in jQuery and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s