-
Sencha User
Error in JSON response from PHP
I am trying to return a simple JSON response from PHP on server. The JSON response seems to be formatted correct - I've validated it, but for some reason I am getting
Uncaught SyntaxError: Unexpected token :
error and my store fails to load.
I've tried setting content type to application/json as mentioned in many forums.
<?php header('content-type: application/json; charset=utf-8');
response seems to be interepreted as MIME type text/html - not sure if this is the problem, but couldn't get that changed.
Here is the JSON response:
{"sb3model":[{"sbfor":"Ayy","sbname":"Har","sbloc":"a"},{"sbfor":"Muruga","sbname":"Ska Sas","sbloc":"b"},{"sbfor":"Gan","sbname":"Maa Gap","sbloc":"c"}]}
Any help will be great!.
Thanks,
ST
-
Sencha User
hi guys, I was able to get the Response Content-Type to be in applicaiton/json MIME type. But still running into this error- JSON is valid- this is driving me nuts,
Uncaught SyntaxError: Unexpected token :
-
Sencha User
folks..it finally worked. being a newbie, every step seems to be a challenge, - but thanks to helpful posts on the web.
here is what I had to do...
After getting the MIME type straight.
I changed the code to implement callback as it is JSONP
echo json_encode(array('sb3m'=>$arr)) // this may be valid for a JSON response.
to
echo $_GET['callback'].'('.json_encode(array('sb3m'=>$arr)).')'; // key here $_GET... as this handles JSONP requests from a different server than responding server.
-
Sencha Premium Member
thanks for sharing.
i had the same troubles working with node express but. this did the trick for me: http://vaboone.wordpress.com/2011/08...de-js-express/
cheers
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules