EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jimprucha on December 13, 2011, 11:35:29 AM



Title: How to request the json data from an IIS server using .Net
Post by: jimprucha on December 13, 2011, 11:35:29 AM
Hi,

I see plenty of examples of loading the json data through a static file. How do we load the datagrid if we need to make a call to the server to get the json data?

An example using jQuery would be great?

Thanks,

Jim


Title: Re: How to request the json data from an IIS server using .Net
Post by: mzeddd on December 14, 2011, 07:34:50 AM
In my PHP code it looks like this:

Code:
$(function(){
$('#testConfigTable').datagrid({
title:'title',
animate:false,
url:'path-to-this-script/jsonLoader.php',
sortName: 'confName',
sortOrder: 'desc',
singleSelect:true,
remoteSort: true,
idField:'confName',
columns:[[
{field:'confName',title:'Name',width:200},
{field:'confDescription',title:'Description',width:320}
]]
});
});
   
AND

Code:
<?php

$rows 
= array();

$query mysql_query("SELECT confName, confDescription FROM configTable ORDER BY confName;");

while(
$item mysql_fetch_array($query)){
$rows[] = $item;
}

echo 
json_encode($rows); 

?>


For .NET should be smth similar

Check this: http://pietschsoft.com/post/2008/02/NET-35-JSON-Serialization-using-the-DataContractJsonSerializer.aspx (http://pietschsoft.com/post/2008/02/NET-35-JSON-Serialization-using-the-DataContractJsonSerializer.aspx)


Title: Re: How to request the json data from an IIS server using .Net
Post by: jimprucha on December 14, 2011, 09:18:25 AM
Here is my code in the aspx page.  It is getting to it as I can see in the log file that it gets the JSON data and I validated it.

Code:
string jsonString = new JavaScriptSerializer().Serialize(fields);
mlog.Info("Here is the JSON String ==> " + jsonString);
Request.ContentType = "application/json; charset=utf-8";
Response.Write(jsonString);

Here is the code to call the datagrid:
Code:
        var frozenColumns = "[[{field:'MappingFieldID',title:'MappingFieldID',width:100,align:'center'},{field:'Field',title:'Field',width:100,align:'left'}]]";
        var columns = "[[{field:'Screen',title:'Screen',width:80,align:'center'},{field:'ErrorMessage',title:'ErrorMessage',width:160,align:'left'},{field:'IsRequired',title:'Is Required',width:100,align:'center'},{field:'TableName',title:'Table',width:80,align:'center'},{field:'ValueType',title:'Value Type',width:80,align:'center'},{field:'FieldId',title:'Field Id',width:100,align:'center'},{field:'Description',title:'Description',width:140,align:'left'},{field:'Schedule',title:'Schedule',width:140,align:'center'},{field:'EditChecks',title:'Edit Checks',width:140,align:'center'},{field:'FieldCalculations',title:'Field Calculations',width:140,align:'center'}]]";
        $(function()
        {
            $('#GridTable').datagrid({
                width: 600,
                height: 350,
                nowrap: true,
                striped: true,
                collapsible: false,
                url: 'GetJSONData.aspx',
                //sortName: 'Field',
                //sortOrder: 'asc',
                idField: 'MappingFieldID',
                fitColumns: false,
                frozenColumns: eval(frozenColumns),
                columns: eval(columns),
                pagination: false,
                rownumbers: false
            });
        });
It loads the table but only the table columns and it shows the "processing while loading" then it stops and I don't know what happens..

Any ideas if this is the correct way to load the JSON data from a .net page?

I also have another way using a webmethod to get the JSON data but how if I have the JSON data could I load it into the datagrid??

Any help either way would be great!!

Thanks,

Jim


Title: Re: How to request the json data from an IIS server using .Net
Post by: frapa02 on January 06, 2012, 04:27:23 AM
I would try to debug with the browser, e.g. Firefox and Firebug, then monitor the http buffers where you can check the response from your server program and that it is the same as in your log. Your server code just needs to print the json string so I am not sure that you should have the Request.ContentType in there since you are not asking the browser to handle this, just ajax.

It might also be worth checking your IIS logs.

Paul.


Title: Re: How to request the json data from an IIS server using .Net
Post by: pacific202 on January 11, 2012, 06:49:36 PM
I'll second the recommendation for using another browser to debug.  The tools that are built into Chrome are amazing for helping to debug this kind of thing.

The easy way to see what's going on is just to drop the url into your address bar.  What does GetJSONData.aspx return?

You could also put custom code into the onLoadError event for the DataGrid.