Forum



00:21

26/09/2012

Hello,
I have WCf service (it is normal WCF service not Ajax enabled) which accepts various parameter. Through Jqgrid in SerializeGridData I can send the parameters to Ajax enabled wcf service. But my normal WCF service dosen't work with this. Is there any way how I can send parameters to my WCF service. I tried lot of things but didn't work.
Please help.
Thanks in advance.
Manju
13:12

Moderators
30/10/2007

Hello,
Sorry, but you do not provide a example?
Why your service can not accept this parameters.
If yyou try with pure ajax does the service accept parameters?
Not sure that I understand the problem
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
17:27

26/09/2012

Thanks for the reply. Yes with pure Ajax service accept the parameter.
Let me give the example:
In VS 2010 I have added WCF service.
Public Function GetInfo(sidx As String, sord As String, page As Integer, rows As Integer, infoid As String, nd As Integer, _search As Boolean)
As InfoDataForJqGrid Implements IInfo.GetInfo
End Function
The binding used is "webHttpBinding".
In Html i'm trying to send the parameter to the WCF service. But not sure how to do this. I have used below option:
function loadGrid() { jQuery("#tblInfo").jqGrid({ url: 'Services/Service.svc/getInfo', postData: { infoid : function () { return "1"; // $("#infoid ").val(); } }, mtype: 'POST', datatype: 'json', ajaxGridOptions: { contentType: "application/json" }, serializeGridData: function (postData) { var propertyName, propertyValue, dataToSend = {}; for (propertyName in postData) { if (postData.hasOwnProperty(propertyName)) { propertyValue = postData[propertyName]; if ($.isFunction(propertyValue)) { dataToSend[propertyName] = propertyValue(); } else { dataToSend[propertyName] = propertyValue } } } return JSON.stringify(dataToSend); }, jsonReader: { root: "d.rows", page: "d.page", total: "d.total", records: "d.records" }, colNames: ['Code', 'Title', 'Price', 'Product Group', 'Edit', 'Status'], colModel: [ { name: 'Code', index: 'Code', width: 75, align: 'center' }, { name: 'Title', index: 'Title', width: 40, align: 'center' }, { name: 'Price', index: 'Price', width: 55 }, { name: 'Product Group', index: 'Product Group', width: 100 }, { name: 'Edit', index: 'Edit', width: 40 }, { name: 'Status', index: 'Status', width: 40}], pager: '#pager', rowList: [10, 20, 30], sortname: 'Code', sortorder: 'desc', rowNum: 10, loadtext: "Loading....", shrinkToFit: false, multiselect: true, emptyrecords: "No records to view", //width: x - 40, height: "auto", rownumbers: true, //subGrid: true, caption: 'Products' }); jQuery("#prodgrid").jqGrid('navGrid', '#pager', { edit: false, add: false, del: true, excel: true, search: false }); //}); }
Now in the seralizeGridData i get the proper string, but service is not getting called.
It gives error "500 INternal server error". This works fine if I have Ajax enabled wcf service.
Please let me know what I'm missing here.
Thanks for quick reply.
Manju
08:46

Moderators
30/10/2007

Hello,
serializeGridData should return the same data as it accept as parameter - i.e not string - with other words replace
return JSON.stringify(dataToSend);
with
return dataToSend;
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
10:33

Moderators
30/10/2007

Hello,
Just for the record - please post what was the problem and how you have resolved it.
Thank you.
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
21:15

26/09/2012

Hello,
I was not able to pass parameters to WCF service. This is how i did it:
function successFunction(jsondata) {
var thegrid = jQuery("#tblInfo")[0];
thegrid.addJSONData(jsondata.GetInfoResult);
}
function getInfo(pdata) {
var data = [];
data.push({ Key: "rows", Value: pdata.rows });
data.push({ Key: "page", Value: pdata.page });
data.push({ Key: "sidx", Value: pdata.sidx });
data.push({ Key: "sord", Value: pdata.sord });
data.push({ Key: "ddlinfostatus", Value: "1" });
data.push({ Key: "search", Value: pdata._search });
var dictObject = { nvp: data };
var _url = "Services/Info.svc/GetInfo"
$.ajax({
url: _url,
data: JSON.stringify(dictObject),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: successFunction,
error: function (jsondata) {
alert('error');
}
});
}
function loadGrid() {
jQuery("#tblinfo").jqGrid({
datatype: function (pdata) {
getInfo(pdata); // calls the function above with 'postData'
},
colNames: ['Sk', Id', ],
colModel: [{ name: sk', index: sk', width: 20 },
{ name: 'id', index: 'id', width: 200 }],
jsonReader: { repeatitems: false,
root: function (obj) { return JSON.parse(obj.rows); },
page: function (obj) { return obj.page; },
total: function (obj) { return obj.total; },
records: function (obj) { return obj.records; },
id: '0',
cell: ''
},
width: 500,
height: 200,
rowList: [10, 20, 30],
rowNum: 10,
sortname: 'sk',
emptyrecords: "No records to view",
sortorder: "asc",
viewrecords: true,
pager: '#pager',
caption: "",
loadtext: "Loading....",
sortable: true
});
}
Thanks,
Manju
Most Users Ever Online: 715
Currently Online:
43 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