Problem with CrunchBase API and jQuery $.getJSON

I am trying to simply send an alert with a "name", but It doesn't seem to work. Advice?

$(document).ready(function() {
$.getJSON("http://api.crunchbase.com/v/1/companies/permalink?name=Google", function(data) {
   alert("Hello: " + data.name);
  });
 });

Here is what the JSON contains:

{"crunchbase_url": "http://www.crunchbase.com/company/google",
 "permalink": "google",
 "name": "Google"}   

Answers


Normally you'd use JSONP here by adding &callback=? to your URL, however a JSONP callback is not supported in this case, from the crunchbase API documentation:

List Entities

To retrieve a list of all of the entities in a certain namespace on CrunchBase, use a URL of the form:

http://api.crunchbase.com/v/1/<plural-namespace>

The plural available namespaces are:

  • companies
  • people
  • financial-organizations
  • products
  • service-providers

This action does not support JavaScript callbacks.

The bottom line is the most important, you'll see that this: http://api.crunchbase.com/v/1/companies/permalink?name=Google&callback=callme still results in regular JSON, not JSONP.


If you're not Crunchbase, you can't send that request. For security reasons, only www.crunchbase.com may send AJAX requests to www.crunchbase.com. (Imagine we were talking about www.bankofamerica.com and I were logged in. It'd be a problem if just any site could send arbitrary requests to www.bankofamerica.com with my cookies attached.)

The API documentation does indicate a JSON-P option, however. If you're interested, you can look up the implementation details, but the important bit is that the JSON-P technique is able to circumvent the domain name restriction because Crunchbase's API will allow you to.

The URL http://api.crunchbase.com/v/1/company/google.js is a similar resource to the one you mentioned, but this particular URL allows you to use JSON-P, whereas the one you posted does not. jQuery allows you to do this easily: pass the URL to $.getJSON as http://api.crunchbase.com/v/1/company/google.js?callback=? (the bit about the callback is important!), and jQuery will fill in the blanks and handle the magic script loading behind the scenes. It's very fancy :)


Need Your Help

I can't update Django's RedirectView. It keeps referring to the old URL with a status of 301 Moved Permenantly

django apache http-status-code-301 django-class-based-views

Sorry if this question was supposed to be in Server Vault. I couldn't really tell whether it's a programming error or a server configuration error.