jQWidgets Forums
jQuery UI Widgets › Forums › Grid › jqxGrid not binding to JSON
This topic contains 3 replies, has 2 voices, and was last updated by realtek 11 years, 8 months ago.
-
Author
-
Hi,
I have a jqxGrid which works fine when binding to a JSON output in PHP I wrote.
I have decided to move it to .NET whereby I have created a asmx web service which outputs a JSON string.
It seems to not load anything in the Grid, however if I change the URL to my PHP JSON output, it works fine, so it would seem my issue is the asmx output from the webservice.
Here is an example of my output when invoking a test:
{“columnsinfo”:[{“FIELDNAME”:”Number”,”DISPLAYNAME”:”Number #”},{“FIELDNAME”:”Description”,”DISPLAYNAME”:”Description Test”},{“FIELDNAME”:”ID”,”DISPLAYNAME”:”ID Number”}],”rowsinfo”:[{“Number”:2,”Description”:”Testing”,”ID”:”1″}]}
I have the “root” in my jQuery to be “rowsinfo”… does anyone know why it may not be filling my grid?
Here is my jQuery:
var url = "webservices/Tesr.asmx/GetRecords"var source = { datatype: 'json', url: url, type: "POST", id: "SEQUENCE", root: 'rowsinfo',// record: 'string', cache: false, columns:[], datafields:[], beforeprocessing: function (data) { var columnsdata = new Array(); var datafieldsdata = new Array(); for (k in data.columnsinfo){ var col={}; col.text = data.columnsinfo[k]["DISPLAYNAME"]; col.datafield = data.columnsinfo[k]["DISPLAYNAME"]; var datafields={}; datafields.name = data.columnsinfo[k]["DISPLAYNAME"]; columnsdata .push(col); datafieldsdata .push(datafields); source.columns = columnsdata; source.datafields = datafieldsdata; } $("#jqxgrid").jqxGrid({columns : source.columns}); }, data: { group: JSON.stringify(checkedGroups), staff: JSON.stringify(checkedStaff), MODULE: selectedModuleSEQ } };
Thanks
Can you verify the json string coming back from the php and the .net services are actually identical? The url you listed says “Tesr.asmx”, I’m assuming that’s supposed to be “Test.asmx” (typo)? Also, is the .net service setting the content type as “application/json” in the response header?
Hi dperry,
Yes they are identical except the first part says “string xmlns…. etc…”
I have this set: [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
It looks like the identically same JSON format so I really don’t understand it. Chrome Developer Tools doesn’t give me any errors or more information.
Yes it was a typo when I created the asmx and I haven’t got round to changing it yet – so it is correct for the time being!
Hi,
OK, I have FINALLY managed to sort it…
From this post here: http://blogs.msdn.com/b/carlosfigueira/archive/2008/04/17/wcf-raw-programming-model-web.aspx
Firstly I moved this to a WCF service so its a bit more up to date and handles some things better.
Secondly, I had simular issues… and this is what resolved it for me.
Although the web service returned what appeard to be JSON, the fact it had “string etc…” wrapped around it meant it was actually returning a XML string with JSON in it.
The only way I could resolve this was to return a Stream, not string.
So use a StreamReadeer like:
byte[] resultBytes = Encoding.UTF8.GetBytes(jsonResult);
return new MemoryStream(resultBytes);and return this to the client. Its working for me now anyway. Thanks for your help though, you got me thinking with the message formats!
-
AuthorPosts
You must be logged in to reply to this topic.