-
2 Jan 2011 1:30 PM #1
extjs grid, json request getting "Uncaught SyntaxError: Unexpected token :" error
extjs grid, json request getting "Uncaught SyntaxError: Unexpected token :" error
Hello,
I have a grid
mygrid.js
I then have a php script ( the getEmails.php ):Code:Ext.onReady(function(){ Ext.QuickTips.init(); var store = new Ext.data.JsonStore({ remoteSort: true, baseParams: {lightWeight:true,ext: 'js'}, autoLoad: {params:{start:1, limit:2}}, //dataType: 'JSON', proxy: new Ext.data.ScriptTagProxy({ url: 'getEmails.php', //url: 'http://www.sencha.com/forum/topics-browse-remote.php' }), reader: new Ext.data.JsonReader({ //totalProperty: 'totalemails', //root: 'emails', //idProperty: 'messageid', fields: [{name:'messageid', type:'int'}, {name:'subject', type:'string'}] }) }); //store.load(); var grid = new Ext.grid.GridPanel({ renderTo: 'emailGrid', width:700, height:500, frame:true, title:'Found Emails', trackMouseOver:false, autoExpandColumn: 'subject', store: store, columns: [new Ext.grid.RowNumberer({width: 30}),{ id: 'messageid', header: "ID", dataIndex: 'messageid', width: 40, sortable:true },{ id: 'subject', header: "Subject", dataIndex: 'subject', width: 420, sortable:true }], bbar: new Ext.PagingToolbar({ store: store, pageSize:500, displayInfo:true }), view: new Ext.ux.grid.BufferView({ // custom row height rowHeight: 34, // render rows as they come into viewable area. scrollDelay: false }) }); });
The json code output looks like this :Code:$emailArray = array(); $emailArray['totalemails'] = $foundmessagescount; $emailArray['emails'] = array(); for ($i = $start; $i < ($limit+$start) && $i < count($search); $i++ ){ $subject = $storage->getMessage($search[$i])->subject; $emailDet = array(); $emailDet['messageid'] = (int)$search[$i]; $emailDet['subject'] = $subject; $emailArray['emails'][]= $emailDet; } $json = json_encode($emailArray); $dec = json_decode($json); echo $json;
{"totalemails":17,"emails":[{"messageid":1047,"subject":"no subject"},{"messageid":1780,"subject":"no subject"},{"messageid":1782,"subject":"no subject"}]}
I keep on getting the "Unexpected Token :" error and the grid won't load.
Any help is MUCH appreciated.
Thanks,
Mike
-
2 Jan 2011 3:14 PM #2
uncomment root in your store, may be your json content some special symbols like < or > ?, also may be you have some spaces in js file(s)
-
2 Jan 2011 3:18 PM #3
Just tried your suggestion, still no go. Any other thoughts? If I put the json response for the example ( the commented out code in the js file, it works ). But the php file seems to be causing the problem maybe?
thanks,
Mike
-
2 Jan 2011 3:25 PM #4
http://dev.sencha.com/deploy/dev/doc...ScriptTagProxyAn implementation of Ext.data.DataProxy that reads a data object from a URL which may be in a domain other than the originating domain of the running page.
Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of the running page, you must use this class, rather than HttpProxy.
The content passed back from a server resource requested by a ScriptTagProxy must be executable JavaScript source code because it is used as the source inside a <script> tag.
In order for the browser to process the returned data, the server must wrap the data object with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy. Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy depending on whether the callback name was passed:An implementation of Ext.data.DataProxy that reads a data object from a URL which may be in a domain other than the originating domain of the running page.
Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of the running page, you must use this class, rather than HttpProxy.
The content passed back from a server resource requested by a ScriptTagProxy must be executable JavaScript source code because it is used as the source inside a <script> tag.
In order for the browser to process the returned data, the server must wrap the data object with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy. Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy depending on whether the callback name was passed.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
2 Jan 2011 3:27 PM #5
Thanks for the quick response, however, this is returning from the same domain ( or am I missing something? ). Does this need to be a js return? How would I do that?
Thanks,
Mike
P.S. Sorry for dumb questions, I'm used to the GWT ext and not pure js.
-
2 Jan 2011 3:37 PM #6
My point was, why are you using a ScriptTagProxy in the first place? Use an HttpProxy.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
2 Jan 2011 3:41 PM #7
OH!! Thanks!! i just tried using
Now its not getting the error but still not showing in the Grid.Code:proxy: new Ext.data.HttpProxy({ url: 'getEmails.php', //url: 'http://www.sencha.com/forum/topics-browse-remote.php' }),
Thanks,
Mike
-
2 Jan 2011 4:04 PM #8
Have you tried removing the stray comma from the end of your URL?
-
2 Jan 2011 4:08 PM #9
@skirtle - Thanks!! Didn't realize that was there. Just tried it, still nada. Do I have to have a renderer for the columns in the grid, or will it auto display simple text?
Also, I am receiving "XHR finished loading: "http://www.mydomain.com/getEmails.php" instead of the error from before if that helps at all.
Thanks,
Mike
-
2 Jan 2011 4:47 PM #10
You don't need to explicitly specify the HttpProxy, if you just specify a url on the store it'll use an HttpProxy by default.
You also don't need to specify the JsonReader, a JsonStore uses one by default. Put the config options for the reader directly on the store instead. You'll need to uncomment the root property from your original example. Something like this:
Code:var store = new Ext.data.JsonStore({ remoteSort: true, baseParams: {lightWeight:true,ext: 'js'}, autoLoad: {params:{start:1, limit:2}}, //dataType: 'JSON', url: 'getEmails.php', totalProperty: 'totalemails', root: 'emails', idProperty: 'messageid', fields: [{name:'messageid', type:'int'}, {name:'subject', type:'string'}] });
Similar Threads
-
Uncaught SyntaxError: Unexpected token
By jaquin in forum Sencha Touch 1.x: DiscussionReplies: 6Last Post: 3 Feb 2011, 4:48 AM -
"getConnectionObject is not a function" error when filling grid with json
By MrGrah in forum Ext 3.x: Help & DiscussionReplies: 8Last Post: 21 Oct 2010, 10:35 AM -
Javascript error "uncaught exception" while using Ext.Direct
By lebesnec in forum Ext.DirectReplies: 1Last Post: 1 Jun 2010, 11:46 PM -
[FIXED][3.??] Ext.Direct "exception" event raises "tid has no properties" error
By j.bruni in forum Ext 3.x: BugsReplies: 8Last Post: 22 Jun 2009, 8:56 PM -
uncaught exception: Error listening for "mousedown"
By rouet in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 13 Mar 2008, 6:18 AM


Reply With Quote