net web forms project and I get data with this format from my ashx.cs http handler file (server side) :
{"total":1,"page":1,"records":10,"userData":{"KoleMoamelat":"1180"},"rows":[{"id":1,"cell":["1"]}]}
and this is a part of the my jqGrid jquery code:
<script type="text/javascript">
var grid;
grid = jQuery("#list").jqGrid({
url: '/Report/Handlers/AdvancedSearch.ashx',
datatype: 'json',
mtype: 'GET',
colNames: [ 'نوع ملک'],
colModel: [
{ name: 'Counter', index: 'Counter', width: 40, align: 'center' },
pager: jQuery('#pager'),
rowList: [5, 10, 20, 50],
rowNum: 10,
height: 120,
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
imgpath: '/scripts/themes/coffee/images',
caption: 'آمار قراردادهای ثبت شده در یک بازه زمانی',
loadComplete: function (data) {
var userData = $("#list").jqGrid("getGridParam", "userData");
document.getElementById("lblKoleMoamelat").innerHTML = userData["KoleMoamelat"];
actually the data for the jqGrid table itself is correct without any problem, but I want to access the userData that returned with the jQgrid columns for this segment of code :
document.getElementById("lblKoleMoamelat").innerHTML = userData["KoleMoamelat"];
but this code doesn't get userData from ashx.cs response (server response) :
var userData = $("#list").jqGrid("getGridParam", "userData");
now in html form the element of Id : lblKoleMoamelat unfortunately shows undefined. I appreciate any help.
Here is the code snippet that should help you access the
userDatafrom the response and update the HTML element with the correct value:You should access the
userDatadirectly from thedataparameter of theloadCompletefunction. TheuserDatais already part of the response data, so you don't need to use thegetGridParammethod to access it.