0

I've been searching arround and I can't retrive JSON information from this example. Can anybody help me please?

var jsonURL = "http://mdc2.cbuc.cat/dmwebservices/index.php?q=dmGetCollectionList/json";

var jqxhr = $.getJSON(jsonURL, function(data) {
  alert("Success!");
  alert(data[0].alias); 
})
.success(function() { alert("second success"); })
.error(function() { alert("error"); })
.complete(function() { alert("complete"); });

jqxhr.complete(function(){ alert("second complete"); });

I've checked the URL and everywhere it says that is valid and well formated...

1
  • 2
    You cannot retrieve JSON from a different domain, only if it is JSONP. Commented Sep 28, 2011 at 14:35

2 Answers 2

1

Since that request is not returning proper jsonp, the browser can't interpret it.

If you have access to that server, it would need to be modified to accept a callback function such as ?callback=cbfunc which would then wrap the json response in a callback function, such as cbfunc(["foo","bar"]);

If you do not have access to that server, you can either use a 3rd party solution such as YQL, or you can build a server-side proxy that will make the request for you. For YQL, here's a page that can help:

http://developer.yahoo.com/yql/console/#h=SELECT%20*%20FROM%20json%20WHERE%20url%3D%22http%3A//mdc2.cbuc.cat/dmwebservices/index.php%3Fq%3DdmGetCollectionList/json%22

choose the json radio button, then at the bottom of the page you'll find a url. just remove the callback=cbfunc part.

This is the url that was generated:

http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20json%20WHERE%20url%3D%22http%3A%2F%2Fmdc2.cbuc.cat%2Fdmwebservices%2Findex.php%3Fq%3DdmGetCollectionList%2Fjson%22&format=json&callback=cbfunc

If the request contains any sensitive data, i would suggest against YQL and for using a server-side script to get the data.

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

1 Comment

Well... The first answer is the reason why I can't retrive JSON and yours is how can I overpass the problem, right? Thanks you both!
1

Is the page running that code hosted on mdc2.cbuc.cat? Otherwise, you're probably running into the same origin policy.

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.