Forum



16:35

26/04/2011

I am using jqgrid with ColdFusion, and it works great. Just have one issue I can't seem to figure out. I'm using the "Prefix serialized JSON with" setting in ColdFusion. (See http://help.adobe.com/en_US/Co.....-750b.html the secureJSON and secureJSONPrefix options) Here's another a link that talks about it http://www.petefreitag.com/item/720.cfm.
It basically just adds some characters to beginning of the JSON string that is sent back like this...
//{“rows”:[{“cell”:[””,10000228637555,”ACSN”,”444657#002”,””,”OPEN”,”GFHGVKJLM”],”ID”:10000228637555},{“cell”:[etc...
Notice the leading //. My question is, is there a way I can manipulate the response before it tries to act on it so I do not receive parseerror? I just want to be able to remove the first [X] number of charaters from the response.
14:48

28/07/2011

gfrobenius said:
I am using jqgrid with ColdFusion, and it works great. Just have one issue I can't seem to figure out. I'm using the "Prefix serialized JSON with" setting in ColdFusion. (See http://help.adobe.com/en_US/Co.....-750b.html the secureJSON and secureJSONPrefix options) Here's another a link that talks about it http://www.petefreitag.com/item/720.cfm.
It basically just adds some characters to beginning of the JSON string that is sent back like this…
//{“rows”:[{“cell”:[””,10000228637555,”ACSN”,”444657#002”,””,”OPEN”,”GFHGVKJLM”],”ID”:10000228637555},{“cell”:[etc...
Notice the leading //. My question is, is there a way I can manipulate the response before it tries to act on it so I do not receive parseerror? I just want to be able to remove the first [X] number of charaters from the response.
Hi
If you simply need to remove the // can you try:
serializeJson( Mid( yourAjaxString , 2 , len(yourAjaxString) )) ;
I have also posted the function that I use to generate my data for each grid. I use this on many grids and it's kinda grown over the years but you can always chop out what you don need.
Regards Ken,
(sorry about the formatting but if you paste into eclipse it will be nice and neat, I promise)
<cffunction
name="fnt_displayStaffDataGrid" access="private" output="true">
<cfargument name="staffData" required="true" type="Any" />
<cfargument name="structArg" required="true" type="struct" />
<cfsilent><cfsetting showdebugoutput="false" />
<cfscript>
// define the local scope
local = {
// count the data rows passed across
dataCount = arguments.staffData.recordCount
//create the looping counter
,cnt_data =
0
// create the image paths and strings
,openImgText =
,closeImgText =
lCase('<img src="..#application.clientSys#mediaimagesicons')'.png" class="profilePicture">'
,str_imagePath =
''
,str_maleProfile =
'profile_male'
,str_femaleProfile =
'profile_female'
,list_maleGender =
'Mr,Sir'
};
// declare the structure to contain the results
local.result = {};
local.result[
// local.result['rows'] = []; <— this does not work here and I don't have a clue why ???? it works everywhere else….
// add the page details to result
local.result[
local.result[
local.result[
// loop over the data and create the jSon values
local.cnt_data = local.cnt_data +
// define the temporay holder for the jSon data
local.row = {};
// create the row and give it a unique ID.
local.row[
// create an array to hold the cell information
local.row[
// select the image profile
local.str_imagePath = local.openImgText & local.str_femaleProfile & local.closeImgText;
}
local.str_imagePath = local.openImgText & local.str_maleProfile & local.closeImgText;
};
// populate the cells with the required information ** removed - local.str_imagePath & ' ' &
// ************************************************
// ************************************************
// add the row to the results
}
//cfdrop(serializeJson(local.result));
'rows'] = arrayNew(1);'page'] = javaCast( 'int', arguments.structArg.pageNumber );'records'] = javaCast( 'int', arguments.structArg.totalRecords );'total'] = javaCast( 'int', arguments.structArg.totalPages );while ( local.cnt_data < local.dataCount ) {1;'id'] = arguments.staffData.staffID[local.cnt_data];'cell'] = [];if ( listFindNoCase( local.list_maleGender, trim(arguments.staffData.staff_title[local.cnt_data]) ) == 0 ) {else {arrayAppend( local.row['cell'], trim(arguments.staffData.staffID[local.cnt_data]) );arrayAppend( local.row['cell'], trim(arguments.staffData.staff_firstName[local.cnt_data]) );arrayAppend( local.row['cell'], trim(arguments.staffData.staff_surname[local.cnt_data]) ); arrayAppend( local.result['rows'], local.row );</cfscript>
 
</cfsilent><cfoutput>#serializeJson(local.result)#</cfoutput><cfabort>
</cffunction>
18:06

26/04/2011

Thanks for your reply but that will not work. (I can also supply my version of the ColdFusion backend if you want it, email me, gordon@psasys.com) Let me see if I can better explain. Your suggestion above was to use ColdFusion mid to simply remove the leading character, but ColdFusion is not in play at all at the point where the problem lies. The grid makes a request to my cfc function, that cfc function does a query, turns the rows into json rows that the jqGrid is expecting, and returns that. When ColdFusion returns that json string is contains some leading charaters that I need to be able to strip out using CLIENT SIDE JQGRID JAVASCRIPT CODE. ColdFusion talking to ColdFusion there is no problem (meaning using ColdFusions SerializeJSON and DeserializeJSON). Doing it that way CF knows to automatically add the leading characters and remove the leading characters, you don't need to do anything. But in my case its not CF talking to CF, its jqGrid (javaScript ajax) talking to CF. So CF is putting the leading characters on the JSON string and I need to know how to remove them using some kind of a jqGrid hook. I guess I'm hoping for an event between events 3 and 4...
Execution order of jqGrid Events...
-
beforeRequest
-
loadBeforeSend
-
serializeGridData
-
loadError (if a error from the request occur - the event 5 and 6 do not execute. If there is no error the event 4. does not execute and we continue to with 5. and 6.)
-
gridComplete
-
loadComplete
00:16

28/07/2011

Hi
Sorry I was not able to help.
I don't mean to state the obvious but are you able to change settings in the administrator?
Have a look under settings is so about half way down.
"Prefix serialized JSON with
Protects web services which return JSON data from cross-site scripting attacks by prefixing serialized JSON strings with a custom prefix"
And un-check that option.
If this does not work you are able to switch off prefixing using the application.cfc or in your cfc. This I have never done but Ray Camden has a post on this.
Other than that... don't forget that CF only prefixes with JS code not written by CF. To put simply, if you used CFajaxProxy to call your CF ajax generator then that would work without having to turn off the function in the administrator.
Sorry if you already knew all this but it's as far as my knowledge stretches. Good luck.
regards
Ken.
00:45

26/04/2011

Thanks, but yeah, I'm aware of the setting and everything works fine when it's off. We will have jqGrid on literally 1000s of screens and don't want to paint ourselves into a corner if down the road we are required to turn this extra security feature on. Removing it on the CF end before sending it back to the jqGrid bypasses that feature all together (but is do-able). Guess I'll have to look "under the jqGrid js hood" and find where the response is coming back and put my own hook in. Thanks.
Most Users Ever Online: 715
Currently Online:
70 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66