PDA

View Full Version : Proxy not working with type 'jsonp' !!!



pm.sreejith
15 Nov 2011, 4:03 AM
Hi All,

I was tried to use proxy with type 'jsonp' in a store. But I'm getting an error like as follows,
"Uncaught SyntaxError: Unexpected token :" :((

I am using ST2.0 with MVC pattern. The code which I wrote is given below:




Store
-------------
Ext.define('Sencha.store.Latestarticles', {
extend : 'Ext.data.Store',
model : 'Sencha.model.Latestarticles',
requires: ['Sencha.model.Latestarticles'],

proxy : {
type : 'jsonp',
url : 'http://192.168.8.128/magazine/getlatestarticles.php',
reader : {
type : 'json',
root : 'articles',
totalCount : 'total'
}
},
autoLoad: true
});

Model
-----------
Ext.define('Sencha.model.Latestarticles', {
extend: 'Ext.data.Model',

fields: [
{name: "articleid", type: "number"},
{name: "catogery", type: "string"},
{name: "image", type: "string"},
{name: "title", type: "string"}
]
});


Response
----------------
{"success":true,"total":10,"articles":[{"articleid":"24","catogery":"CARS, BIKES, BOATS & PLANES","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/n1_0.jpg","title":"The man behind Ferrari's new<br\/>tailor made service"},{"articleid":"21","catogery":"SPORT","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/sachin.jpg","title":"Sachin Tendulkar - The legend"},{"articleid":"16","catogery":"HOUSE & GARDEN","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/mn1.jpg","title":"How does a garden really grow?"},{"articleid":"14","catogery":"ART & COLLECTING","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/art.jpeg","title":"A torrent of new work from a<br\/>late-flowering artist"},{"articleid":"18","catogery":"WATCHES & JEWELLERY","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/wtc.jpg","title":"It's the ultimate selection of<br\/>fine watches"},{"articleid":"20","catogery":"HEALTH & GROOMING","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/art.jpg","title":"Spa junkie at... bodyism"},{"articleid":"17","catogery":"LIFESTYLE","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/n1.jpg","title":"The Aesthete"},{"articleid":"23","catogery":"PHILANTHROPY","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/mn1_0.jpg","title":"Where are India's great<br\/>philanthropists?"},{"articleid":"19","catogery":"FASHION","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/n3.jpg","title":"Confessions of a Boden addict"},{"articleid":"22","catogery":"FOOD & DRINK","image":"http:\/\/192.168.8.128\/bo-magazine\/sites\/default\/files\/kp.jpg","title":"Super delicious food in an<br\/>cool restaurant"}]}



Please go through the code and let me know...:-?

Advance thanks...

fabio3534
16 Nov 2011, 2:59 PM
you're forgetting the callback function.
use the parameter
callbackKey: ' myCallback'

on server side, concat the json with your callback function, passed by GET
php example:

echo $_GET['myCallback']."(". json_encode(your_json). ")";