Solved

Load Jason $.ajax

Posted on 2014-11-26
2
110 Views
Last Modified: 2014-11-27
I have two different URL's to JSON data - one works and the other does not.
My call to the openweathermap works fine, but the  citybikeNYC fails.
It looked to me like the structure was the same so not sure why this is happening.


//myURL = 'http://www.citibikenyc.com/stations/json';


myURL = 'http://api.openweathermap.org/data/2.5/find?lat=42.033449&lon=-93.630885&cnt=15&units=imperial';

//load data from external source
	$.ajax({
		url: myURL,
		dataType: 'json',
    	jsonp: false
	}).done(function(data) {
		console.log(data);
	console.log(data.count + ' data count');
		

	});

Open in new window

0
Comment
Question by:lvmllc
2 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40467444
Thats a cross origin policy error, they need to allow you to access the api or use jsonp
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40467498
you need your server to load this data, so instead using their address in your code, use your.
an easy server code with php :

proxy.php :
<?PHP
   header('Content-type: application/json');
   echo file_get_contents("http://www.citibikenyc.com/stations/json");
?>

Open in new window


your code now look like :
//myURL = 'http://www.citibikenyc.com/stations/json';
//myURL = 'http://api.openweathermap.org/data/2.5/find?lat=42.033449&lon=-93.630885&cnt=15&units=imperial';

myURL = 'proxy.php'; // if needed, change this the right path : where you put the proxy.php in your website folder

//load data from external source
	$.ajax({
		url: myURL,
		dataType: 'json',
    	jsonp: false
	}).done(function(data) {
		console.log(data);
	console.log(data.count + ' data count');
		

	});

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now