I can successfully hit this endpoint via my browser as well as RESTclient plugins I have for Chrome (ie Postman) https://transitdata.phoenix.gov/api/tripupdates?format=json
However when I send a GET request from my app I get:
No 'Access-Control-Allow-Origin' header is present on the requested resource
Example GET request
jQuery.ajax({
url: 'https://transitdata.phoenix.gov/api/tripupdates?format=json',
type: 'GET',
success: function (data) {
console.log(data);
}
});
If I send a JSONP (with callback) I still get:
Unexpected Token :
Example JSONP request
$.ajax({
url: "https://transitdata.phoenix.gov/api/tripupdates?format=json&callback=parseResponse",
dataType: "jsonp",
success: function( response ) {
console.log( response ); // server response
}
});
I am not sure what I am doing wrong here. Any advice?
The output of the server isn't actually wrapping the result in your callback function, so it appears the server doesn't support JSONP
.
The next best option might be having a local proxy to go and fetch that data for you.
EDIT
The server returns raw JSON:
{"header":{"gtfs_realtime_version":"1","incrementality" //snip
where what you would expect from a supporting server with JSONP
would be:
callbackName({"header":{"gtfs_realtime_version":"1","incrementality" //snip
Your proxy server would be on your same domain, and would go fetch that JSON for you, and then return it to your script, avoiding the cross-domain issues you're seeing.