Solved

jTable jquery with asp .net

Posted on 2013-01-16
2
2,877 Views
Last Modified: 2013-01-16
Hi-

I am trying to get jtable working with .net 4.0 but cant seem to get it running...

Here is my code:

_____________________________________________________________________________________________
<WebMethod()> _
    <ScriptMethod(UseHttpGet:=False, ResponseFormat:=Script.Services.ResponseFormat.Json)> _
    Public Function GetPeople() As String
        Dim people As String = "{""Result"":""OK"",""Records"":[{""PersonId"":1,""Name"":""Benjamin Button"",""Age"":17,""RecordDate"":""\/Date(1320259705710)\/""},{""PersonId"":2,""Name"":""Douglas Adams"",""Age"":42,""RecordDate"":""\/Date(1320259705710)\/""},{""PersonId"":3,""Name"":""Isaac Asimov"",""Age"":26,""RecordDate"":""\/Date(1320259705710)\/""},{""PersonId"":4,""Name"":""Thomas More"",""Age"":65,""RecordDate"":""\/Date(1320259705710)\/""}]}"
        Return people
    End Function
_______________________________________________________________________________________________
The web service returns:
{"d":"{\"Result\":\"OK\",\"Records\":[{\"PersonId\":1,\"Name\":\"Benjamin Button\",\"Age\":17,\"RecordDate\":\"\\/Date(1320259705710)\\/\"},{\"PersonId\":2,\"Name\":\"Douglas Adams\",\"Age\":42,\"RecordDate\":\"\\/Date(1320259705710)\\/\"},{\"PersonId\":3,\"Name\":\"Isaac Asimov\",\"Age\":26,\"RecordDate\":\"\\/Date(1320259705710)\\/\"},{\"PersonId\":4,\"Name\":\"Thomas More\",\"Age\":65,\"RecordDate\":\"\\/Date(1320259705710)\\/\"}]}"}
______________________________________________________________________________________________
And my jquery/jtable code:
$(document).ready(function () {

     $('#myjtable').jtable({
         title: 'Table of people',
         actions: {
             listAction: '/GettingStarted/PersonList',
             createAction: '/GettingStarted/CreatePerson',
             updateAction: '/GettingStarted/UpdatePerson',
             deleteAction: '/GettingStarted/DeletePerson'
         },
         fields: {
             PersonId: {
                 key: true,
                 list: false
             },
             Name: {
                 title: 'Author Name',
                 width: '40%'
             },
             Age: {
                 title: 'Age',
                 width: '20%'
             },
             RecordDate: {
                 title: 'Record date',
                 width: '30%',
                 type: 'date',
                 create: false,
                 edit: false
             }
         }
     });

     $('#myjtable').jtable('load');


         });

_____________________________________________________________________________________________

I always seem to get error on the data load.

Any help would be appreciated
0
Comment
Question by:doctor069
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38783825
Use :
$(document).ready(function () {

     $('#myjtable').jtable({
         title: 'Table of people',
         actions: {
              listAction: '/GettingStarted/PersonList',
             createAction: '/GettingStarted/CreatePerson',
             updateAction: '/GettingStarted/UpdatePerson',
             deleteAction: '/GettingStarted/DeletePerson'
         },
         fields: {
             PersonId: {
                 key: true,
                 list: false
             },
             Name: {
                 title: 'Author Name',
                 width: '40%'
             },
             Age: {
                 title: 'Age',
                 width: '20%'
             },
             RecordDate: {
                 title: 'Record date',
                 width: '30%',
                 type: 'date',
                 create: false,
                 edit: false
             }
         }
     });

     $.ajaxSetup({
            dataFilter: function(data) {
                  var msg = jQuery.parseJSON(data);
                  if (msg.hasOwnProperty('d'))
                        return msg.d;
                  else
                        return msg;
            }
      });


    $('#myjtable').jtable('load');


});

More info here : http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/
0
 

Author Closing Comment

by:doctor069
ID: 38784310
Perfect! Thanks you very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question