ExtJS Error: invalid label error while using ScriptTagProxy for JSON data in Paging Grid Example

You can also read this post if you are getting above error while using ScriptTagProxy.

With little bit modification i was trying to use Paging Grid Example from ExtJS. And that where i was getting following error:

invalid label
    {"success":true,"totalCount":

Actually it was not filling my grid, while examining with firebug i got above error. After banging my head over internet i found the reason ;).
Actually it is using ScriptTagProxy to get json data from server. I was sending pure json from server which is not the correct way. ScriptTagProxy sends a url parameter called “callback” which is function name. You need to take this param and form a parameter call. For example callback=fun1 is comming from server, then what you need to do is enclose your json with fun1(yourJSON) call.
like:
fun1({—-your json—-});

Following is an example of ASP.Net code for it:

 String json_string= //"some json here";
 String callback_function_name= Request.Params.Get("callback");
 String response_string = "";
 if (!String.IsNullOrEmpty(callback_function_name))
 {
 response_string = callback_function_name + "(" + json_string + ")";
 }
 else
 {
 response_string = json_string;
 }
 Response.Write(response_string);

you can see the difference of data comming from server for Paging Grid Example. Open following two url:

http://extjs.com/forum/topics-browse-remote.php
http://www.extjs.com/forum/topics-browse-remote.php?callback=fun_1

After examining the data on your browser you will see that, first url is giving pure json, while second one is giving json enclosed in fun_1() function call. ScriptTagProxy is expecting the second data not the pure json one.

If you have any suggestions please feel free to comment.

Published in: on December 2, 2009 at 7:47 pm  Comments (6)  
Tags: , , ,