1

jQuery has cool methods like getJSON, get and load. However all of them in the end make AJAX call.

I am trying to access API www.eventsinindia.com/cities/mumbai/events.js?month=2009-05 .

This API call returns the data in JSON format.

I could not find any way to call this API from jQuery and to get the output data in JSON format. I keep getting Access to restricted URI denied" code: "1012 error because jQuery is trying to make an AJAX call. AJAX call from a standalone page to a server is forbidden.

3 Answers 3

2

As it's on a different domain, are you using a JSONP callback?

http://docs.jquery.com/Ajax/jQuery.getJSON

As of jQuery 1.2, you can load JSON data located on another domain if you specify a JSONP callback, which can be done like so: "myurl?callback=?". jQuery automatically replaces the ? with the correct method name to call, calling your specified callback. This callback parameter may vary depending on API, for instance Yahoo Pipes requires "_callback=?"

Sign up to request clarification or add additional context in comments.

1 Comment

JSONP also has to be supported on the server-side. The normal JSON response should be wrapped inside the value of the url-parameter. So if you have myurl?callback=a32b5c2 the result should look something like: a32b5c2( {} );
1

If it's not a cross-domain request, you just need:

jQuery.getJSON("/cities/mumbai/events.js?month=2009-05", function(json) {
    alert(json[0]);
});

Comments

0

As @ceejayoz suggested JSONP technique must be used to access data on different domain. But in order for this to work the server side script must be JSONP enabled which means that it must accept a parameter that will define a client postback function name to prepend to the JSON data. If this is not the case you need to write a server script on the domain that is hosting your client script to serve as a bridge to the foreign domain.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.