Solved

Load Jason $.ajax

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Numbers in JQuery file 11 66
Bootstrap date picker V2 date restriction 6 38
ajax to record click 3 16
Returning errors to display in a dialog box - Ajax, Json, Php 16 34
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

830 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