jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Error : Invalid JSON primitive
Tagged: datagrid, jquery datagrid, jqxgrid
This topic contains 4 replies, has 3 voices, and was last updated by simpleweb 12 years ago.
-
Author
-
I am getting “Invalid JSON primitive” error while sending the parameters to a webservice method. Here’s the code :
source = {
datatype: “json”,
datafields: [
{ name: ‘Kontonummer’, type: ‘string’ },
{ name: ‘Navn’, type: ‘string’ },
{ name: ‘Adresse1’, type: ‘string’ },
{ name: ‘Adresse2’, type: ‘string’ },
{ name: ‘Adresse3’, type: ‘string’ },
{ name: ‘UserCount’, type: ‘string’ },
{ name: ‘CCOrderEmail’, type: ‘string’ }
],
formatdata: function (data) {
$(‘#page’).BlockUI(‘Loading….’);
var num = parseInt(data.pagenum) + parseInt(1);
var checked = $(‘#chkBrugere’).is(‘:checked’);
return {
Kontonummer: $(‘#txtKontonummer’).val(), WebShopBrugere: checked, Navn: $(‘#txtNavn’).val(), FreeText: $(‘#txtFreeText’).val(), Department: $(‘#ddlAfdelinglist’).val(), PageSize: data.pagesize, PageNumber: num
}
},
cache: false,
root: ‘Debitors’,
url: ‘/ajax/webshop-helper.aspx/GetDebtors’
};dataAdapter = new $.jqx.dataAdapter(source,
{
contentType: ‘application/json; charset=utf-8’,
downloadComplete: function (data, textStatus, jqXHR) {
var sResponse = $.parseJSON(data.d);
var dResponse = $.parseJSON(sResponse.ResponseData);if ($(“#page”).isMasked()) {
$(‘#page’).UnBlockUI();
}if (dResponse != null) {
source.totalrecords = dResponse.TotalRecords;
return dResponse.Debitors;
} else {
source.totalrecords = “0”;
return null;
}
},
loadComplete: function () {
if ($(“#page”).isMasked()) {
$(‘#page’).UnBlockUI();
}
}
});$(“#accountlist”).jqxGrid({
width: 1300,
autoheight: true,
source: dataAdapter,
columnsresize: true,
enabletooltips: true,
virtualmode: true,
pageable: true,
pagesize: 100,
pagesizeoptions: [‘100’, ‘250’, ‘500’],
showdefaultloadelement: false,
rendergridrows: function (args) {
return args.data;
},
columns: [
{ text: ‘Kontonummer’, datafield: ‘Kontonummer’, width: 100 },
{ text: ‘Navn’, datafield: ‘Navn’, width: 200 },
{ text: ‘Adresse1’, datafield: ‘Adresse1’, width: 225 },
{ text: ‘Adresse2’, datafield: ‘Adresse2’, width: 200 },
{ text: ‘Adresse3’, datafield: ‘Adresse3’, width: 200 },
{ text: ‘Usercount’, datafield: ‘UserCount’, width: 75, cellsalign: ‘center’ },
{ text: ‘CCOrderEmail’, datafield: ‘CCOrderEmail’, width: 200 }
]
});When i make a call to a WEBMETHOD using the above code it struck and throw “Invalid JSON primitive” error. The following section of SOURCE object is responsible to send the parameters to the WEBMETHOD :
formatdata: function (data) {
$(‘#page’).BlockUI(‘Loading….’);
var num = parseInt(data.pagenum) + parseInt(1);
var checked = $(‘#chkBrugere’).is(‘:checked’);
return {
Kontonummer: $(‘#txtKontonummer’).val(), WebShopBrugere: checked, Navn: $(‘#txtNavn’).val(), FreeText: $(‘#txtFreeText’).val(), Department: $(‘#ddlAfdelinglist’).val(), PageSize: data.pagesize, PageNumber: num
}
}I think its not able to send the data in correct JSON format to METHOD.
Thanks,Ravi Joshi
Hi Ravi Joshi,
For sending custom params with jqxGrid see this topic: jquery-grid-extra-http-variables.htm.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter,
I have changed my SOURCE object as following :
source = { datatype: "json", type: 'POST', datafields: [ { name: 'Kontonummer', type: 'string' }, { name: 'Navn', type: 'string' }, { name: 'Adresse1', type: 'string' }, { name: 'Adresse2', type: 'string' }, { name: 'Adresse3', type: 'string' }, { name: 'UserCount', type: 'string' }, { name: 'CCOrderEmail', type: 'string' } ], formatdata: function (data) { $('#page').BlockUI('Loading....'); var num = parseInt(data.pagenum) + parseInt(1); var checked = $('#chkBrugere').is(':checked'); return "{'Kontonummer': '" + $('#txtKontonummer').val() + "', 'WebShopBrugere': '" + checked + "', 'Navn': '" + $('#txtNavn').val() + "', 'FreeText': '" + $('#txtFreeText').val() + "', 'Department': '" + $('#ddlAfdelinglist').val() + "', 'PageSize': '" + data.pagesize + "', 'PageNumber': '" + num + "'}"; }, cache: false, root: 'Debitors', url: '/ajax/webshop-helper.aspx/GetDebtors' };
But getting same error.
It’s only working when I have blank values in input controls.Thanks.
Don’t worry I got it working now. There was a mistake from my side.
Ravi J
Hi Robby,
Can you explain how you resolved the issue? I have similar problem, where when I pass more than one param, I get the same error Invalid JSON primitive.
Here is how mine look like
var theme = getDemoTheme();
var url = “GetData.asmx/GetCustomerDetail”;
var jsData = ‘{CustID:1,status:1}’;// prepare the data
var source =
{
type: “GET”,
datatype: “json”,
datafields: [
{ name: ‘custID’ },
{ name: ‘sCustname’ },
{ name: ‘status’ },
{ name: ‘address’ }
],
async: false,
data: jsData,
url: url};
thanks
-
AuthorPosts
You must be logged in to reply to this topic.