View Full Version : Ext.data.JsonP request Unexpected token :

29 Mar 2012, 7:40 AM
Hi folks.
I want to make call to authenticate user and get back token in json file. I use Ext.data.JsonP but when I call it display Uncaught SyntaxError: Unexpected token : in browser.
I can't use Ext.Ajax because it's on another domain.
Here is code:

url : 'myurl',

success : function(result) {

failure : function(result) {
callback : function(result) {

And this is expected result:


Can somebody tell me what's causing Unexpected token : error?
Or other way how to get response.

29 Mar 2012, 8:08 AM

This response is not valid JSONP. It needs to be wrapped by a callback function.

29 Mar 2012, 8:21 AM
Thanks. So how can I get this response if it's not valid jsonp and Ext.Ajax.request is not working because of cross domain violation?

29 Mar 2012, 12:03 PM
I don't want to sound snarky, but can you ask the remote server to give you a valid JSONP response?

I'm assuming you don't have control over that remote server, but some web services allow you to choose a response type (JSON, XML, JSONP, etc)

Another option would be to create a server-side proxy on your domain. Have this proxy call the remote server for you... then you can use Ext.Ajax to connect to your local domain proxy.

29 Mar 2012, 1:51 PM
How is it possible that this doesn't work because it's not valid JsonP file but example from sencha works

// Make the JsonP request
url: 'http://free.worldweatheronline.com/feed/weather.ashx',
callbackKey: 'callback',
params: {
key: '23f6a0ab24185952101705',
q: '94301', // Palo Alto
format: 'json',
num_of_days: 5
success: function(result) {
// Get the weather data from the json object result
var weather = result.data.weather;


Data are not valid JsonP file but only Json.
You can see data at http://free.worldweatheronline.com/feed/weather.ashx?key=23f6a0ab24185952101705&q=94301&num_of_days=5&format=json

29 Mar 2012, 6:02 PM
The example code also sends a callback key.

Look here: http://free.worldweatheronline.com/feed/weather.ashx?key=23f6a0ab24185952101705&q=94301&num_of_days=5&format=json&callback=foo