JSONP call showing "Uncaught SyntaxError: Unexpected token:

Here is my code

$.ajax({ url: 'https://api.flightstats.com/flex/schedules/rest/v1/json/flight/AA/100/departing/2013/10/4?appId=19d57e69&appKey=e0ea60854c1205af43fd7b1203005d59&callback=?', dataType: 'JSONP', jsonpCallback: 'jsonCallback', type : 'GET', async: false, crossDomain: true, success: function(data) { console.log(data); } }); 

What am I doing wrong? Should I add or change anything here? Any help would be greatly appreciated. Thanks

+42
jquery jsonp
Oct 03 '13 at 17:57
source share
3 answers

Working violin:

http://jsfiddle.net/repjt/

 $.ajax({ url: 'https://api.flightstats.com/flex/schedules/rest/v1/jsonp/flight/AA/100/departing/2013/10/4?appId=19d57e69&appKey=e0ea60854c1205af43fd7b1203005d59', dataType: 'JSONP', jsonpCallback: 'callback', type: 'GET', success: function (data) { console.log(data); } }); 

I had to manually configure the callback on callback , as it seems to support all remote services. I also changed the url to indicate that I wanted jsonp.

+44
03 Oct '13 at 18:13
source share
β€” -

You are trying to access JSON, not JSONP.

Pay attention to the difference between your source:

https://api.flightstats.com/flex/schedules/rest/v1/json/flight/AA/100/departing/2013/10/4?appId=19d57e69&appKey=e0ea60854c1205af43fd7b1203005d59&callback= ?

And the actual JSONP (wrapping function):

http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=processJSON&tags=monkey&tagmode=any&format=json

Search for JSON + CORS / Cross Domain Policy and you will find hundreds of SO threads in this thread.

+16
Oct 03 '13 at 18:14
source share

I run this

 var data = '{"rut" : "' + $('#cb_rut').val() + '" , "email" : "' + $('#email').val() + '" }'; var data = JSON.parse(data); $.ajax({ type: 'GET', url: 'linkserverApi', success: function(success) { console.log('Success!'); console.log(success); }, error: function() { console.log('Uh Oh!'); }, jsonp: 'jsonp' }); 

And edit the title in the answer

'Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE'

'Access-Control-Max-Age', '3628800'

'Access-Control-Allow-Origin', 'websiteresponseUrl'

'Content-Type', 'text / javascript; encoding = UTF-8 '

-2
Aug 6 '15 at 20:54
source share



All Articles