Solved

Load Jason $.ajax

Posted on 2014-11-26
2
115 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Retrieve values of an HTML form using JQUERY 2 39
Animated .jpg? 13 62
form button worked now it doesnt anymore 9 42
Jquery get each value 2 17
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

863 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

20 Experts available now in Live!

Get 1:1 Help Now