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

How do I require files in other directory branches?

php recursion require require-once

When I try to use require or require_once, it will work fine if the file to be required is in the same subdirectory, but the moment it sees a file outside of their subdirectory, it generates a fatal

calling external js twice

javascript internet-explorer external

Is it possible to use external js files and jquery twice on the one html doc? I have the first one running but the second time it calls it doesn't work. Also the external js doesn't work when opene...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.