DataTable NOT Loading JSON Data

DataTable NOT Loading JSON Data

benpeterbenpeter Posts: 14Questions: 5Answers: 0
edited December 2014 in Free community support

I have a table with an id viewData on a file named userDetails.aspx with the implementation:

User ID User Name
User ID User Name

In the codebehind, i have a function called getJSONData() with the implementation:

public string getJSONData()
{

            adapter = new SqlDataAdapter("SELECT UserID, UserName FROM tumUsers", aCon);
            DataTable users = new DataTable();
            adapter.Fill(users);
            List<Dictionary<string,object>> rows= new List<Dictionary<string,object>>();
            Dictionary<string, object> row;
            foreach(DataRow data in users.Rows)
            {
                row=new Dictionary<string,object>();
                foreach (DataColumn aCol in users.Columns)
                {
                    row.Add(aCol.ColumnName,data[aCol]);
                }
                rows.Add(row);
            }
            string json = JsonConvert.SerializeObject(rows);

            return json;

    }

On another folder, i have a script names ctxr.js where i have this code:

$("#userviewtable").dataTable({
"processing": true,
"serverSide": true,
"ajax": "../userDetails.aspx/getJSONData"
});

THE PROBLEM:

Data is not being loaded into my table. I am a novice here. Pls help

Answers

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    "serverSide": true

    Doesn't look like you have implemented all of the parameters required for server-side processing.

    Do you need server-side processing? Are you working with 50K+ rows? If not, why is it enabled?

    Also, what is the JSON data being returned by the server?

    Allan

  • benpeterbenpeter Posts: 14Questions: 5Answers: 0

    allan: No JSON data is being returned! Is it correct to execute a method inside an asp.net page (.aspx) using a statement like "../userDetails.aspx/getJSONData"? It seems that is where am getting it wrong. Its returning nothing.
    Yes i need the datatable to do an uplifting job for me please, thus i need a server side processing

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Is it correct to execute a method inside an asp.net page (.aspx) using a statement like "../userDetails.aspx/getJSONData"?

    Yes, as long as the routing on the server is set up for that. You may need to set the contentType header, which I've seen a number of .NET folks need to do to get the framework to respond to JSON. Beyond that, it would be worth asking on a .NET specific forum I think.

    Allan

  • benpeterbenpeter Posts: 14Questions: 5Answers: 0

    Allan: Than why is my ajax: not returning any data?

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    No idea I'm afraid :-). I would need to be able to see the project. But as I say, you would be better asking on a .NET forum where someone a lot more knowledgeable about it that me will be able to help.

    Allan

  • benpeterbenpeter Posts: 14Questions: 5Answers: 0

    Now the error i am getting from the above is:

    {"Message":"Invalid JSON primitive: draw.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}

    What is it that i am getting wrong here! Kindly help. Am a novice

  • benpeterbenpeter Posts: 14Questions: 5Answers: 0

    Then when i add the ajax property data as "data": JSON.stringfy("{}") i get the error:

    {"Message":"Invalid JSON primitive: %22\u00261=%7B\u00262=%7D\u00263=%22\u0026draw=1\u0026columns%5B0%5D%5Bdata%5D=0\u0026columns%5B0%5D%5Bname%5D=\u0026columns%5B0%5D%5Bsearchable%5D=true\u0026columns%5B0%5D%5Borderable%5D=true\u0026columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=\u0026columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false\u0026columns%5B1%5D%5Bdata%5D=1\u0026columns%5B1%5D%5Bname%5D=\u0026columns%5B1%5D%5Bsearchable%5D=true\u0026columns%5B1%5D%5Borderable%5D=true\u0026columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=\u0026columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false\u0026columns%5B2%5D%5Bdata%5D=2\u0026columns%5B2%5D%5Bname%5D=\u0026columns%5B2%5D%5Bsearchable%5D=true\u0026columns%5B2%5D%5Borderable%5D=true\u0026columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=\u0026columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false\u0026columns%5B3%5D%5Bdata%5D=3\u0026columns%5B3%5D%5Bname%5D=\u0026columns%5B3%5D%5Bsearchable%5D=true\u0026columns%5B3%5D%5Borderable%5D=true\u0026columns%5B3%5D%5Bsearch%5D%5Bvalue%5D=\u0026columns%5B3%5D%5Bsearch%5D%5Bregex%5D=false\u0026columns%5B4%5D%5Bdata%5D=4\u0026columns%5B4%5D%5Bname%5D=\u0026columns%5B4%5D%5Bsearchable%5D=true\u0026columns%5B4%5D%5Borderable%5D=true\u0026columns%5B4%5D%5Bsearch%5D%5Bvalue%5D=\u0026columns%5B4%5D%5Bsearch%5D%5Bregex%5D=false\u0026columns%5B5%5D%5Bdata%5D=5\u0026columns%5B5%5D%5Bname%5D=\u0026columns%5B5%5D%5Bsearchable%5D=true\u0026columns%5B5%5D%5Borderable%5D=true\u0026columns%5B5%5D%5Bsearch%5D%5Bvalue%5D=\u0026columns%5B5%5D%5Bsearch%5D%5Bregex%5D=false\u0026columns%5B6%5D%5Bdata%5D=6\u0026columns%5B6%5D%5Bname%5D=\u0026columns%5B6%5D%5Bsearchable%5D=true\u0026columns%5B6%5D%5Borderable%5D=true\u0026columns%5B6%5D%5Bsearch%5D%5Bvalue%5D=\u0026columns%5B6%5D%5Bsearch%5D%5Bregex%5D=false\u0026order%5B0%5D%5Bcolumn%5D=0\u0026order%5B0%5D%5Bdir%5D=asc\u0026start=0\u0026length=10\u0026search%5Bvalue%5D=\u0026search%5Bregex%5D=false.","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"}

    Which argument is not parsed among the arguments that are send to the server?

This discussion has been closed.