PDA

View Full Version : What is wrong with my JSON?



mzagzoog
26 Jul 2010, 9:51 PM
Hello everyone,

I am trying for two days to solve this issue with no success

The following URL will return json data
http://www.a97abi.com/REST/broadcast.php?action=getBroadcastByPage&page=1&callback=Ext.util.JSONP.callback

Using the twitter example to retrieve the JSON data, I get the following error:
Uncaught SyntaxError: Unexpected token :

the Response Headers are:
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Encoding:gzip
Content-Type:application/json
Date:Tue, 27 Jul 2010 05:46:07 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:Apache/1.3.42 (Unix) PHP/4.4.9 mod_gzip/1.3.26.1a mod_log_bytes/1.2 mod_bwlimited/1.4 mod_ssl/2.8.31 OpenSSL/0.9.7a
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-Powered-By:PHP/4.4.9

Can you guys help me solve this issue?

Thank you

evant
26 Jul 2010, 9:56 PM
Because the broadcast page doesn't listen to the JSONP callback argument.

http://en.wikipedia.org/wiki/JSON#JSONP

mzagzoog
26 Jul 2010, 11:04 PM
Thank you Evant for your support
I am not clear yet..

At this point I am requesting the json page from within the same server/domain using the twitter example

var refresh= function() {
Ext.util.JSONP.request({
url: 'http://www.a97abi.com/REST/broadcast.php',
callbackKey: 'callback',
params: {
action: 'getBroadcastByPage',
page: '1'

},
callback: function(data) {
alert("fg");
data = data.results;
timeline.update(data);
}
});
};

Do i still need JSONP?

evant
27 Jul 2010, 12:08 AM
Then you don't need to JSONP. As you read in that link, JSONP is only for cross domain.

mzagzoog
27 Jul 2010, 1:45 AM
We are back to zero :)

Why am I getting an ERROR ,Uncaught SyntaxError: Unexpected token?

The JSON results are valid!

evant
27 Jul 2010, 1:54 AM
So what code are you using?

Post your code and the exact json response.

mzagzoog
27 Jul 2010, 1:58 AM
The json response is

{"results":[{"id":"10512","userId":"217868"},{"id":"10511","userId":"227890"},{"id":"10510","userId":"225183"},{"id":"10509","userId":"227934"},{"id":"10508","userId":"227890"},{"id":"10507","userId":"229426"},{"id":"10506","userId":"217868"},{"id":"10505","userId":"223724"},{"id":"10504","userId":"227890"},{"id":"10503","userId":"227934"},{"id":"10502","userId":"227934"},{"id":"10501","userId":"223724"},{"id":"10500","userId":"227890"},{"id":"10499","userId":"227934"},{"id":"10498","userId":"227890"},{"id":"10497","userId":"228352"},{"id":"10496","userId":"227934"},{"id":"10495","userId":"227934"},{"id":"10494","userId":"227890"},{"id":"10493","userId":"227833"}]}

the code is

var refresh= function() {
Ext.util.JSONP.request({
url: 'http://www.a97abi.com/REST/broadcast.php',
callbackKey: 'callback',
params: {
action: 'getBroadcastByPage',
page: '1'
},
callback: function(data) {
data = data.results;
timeline.update(data);
}
});
};


you can test the page
http://www.a97abi.com/touch

you will get the error when you click on the refreash button.

I am using Google Chrome.. you can also see the json Content using the Developer Tools.

Thank you evant for your help

evant
27 Jul 2010, 2:30 AM
As I said, if you're doing a request on the same domain, you don't use JSONP.