1

I just think this is my variable getting data from database
I declare Description properties in separate class

public class Description
{
  public int DesID{set;get;}
  public string Description{
} 

C# Coding : Data

[WebMethod]    
    public static List<Description> Data()
    {
      List<Description> listDescription = new List<Description>();
      Description d1=new Description()
       {
         DesID=1,
         Description ="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz";
       };
      Description d2=new Description()
       {
         DesID=2,
         Description ="thanks for your response"
       };
    listDescription.add(d1);
    listDescription.add(d2);
    }

JSON :

 $(document).ready(function () {
            $(function () {

                $.ajax({

                    contentType: 'application/json; charset=utf-8',
                    url: 'WebForm1.aspx/Data',
                    dataType: 'json',
                    method: 'post',
                    success: function (data) {
                        for (var i = 0; i < data.d.length; i++) {

                            $('#divdisplay').append("<div>Description ID : "+ data.d[i].DesID+"<br/>Description : "+data.d[i].Description+</div>");
                        }
                    },
                    error: function (result) {
                        alert('Error');
                    }
                });

            });

Important Note :-

I already tried this below code, but it is not working

$(data.d[i].Description).val().substr(1,5); And
data.d[i].Description.val().substr(1,5)
$(data.d[i].Description).val().substring(1,5); And
data.d[i].Description.val().substr
Orlando Herrera
  • 3,481
  • 1
  • 34
  • 44
Sri
  • 174
  • 2
  • 14
  • For us to help you, you need to rewrite your question. 1) Are you asking how to send JSON from c#? If so, you should fix your c# compilation errors, add the tag [tag:c#], and explain what is not working. 2) Or are you asking how to parse JSON in JavaScript? If so, the c# code is irrelevant. You should [edit](https://meta.stackexchange.com/questions/21788/how-does-editing-work) your post to remove it and instead include the JSON returned by the server. Fix the tags to be [tag:javascript] and [tag:json] and others as required. See [How to ask](https://stackoverflow.com/help/how-to-ask). – dbc May 02 '16 at 21:48
  • Actually, does [how to parse json data with jquery / javascript?](http://stackoverflow.com/questions/8951810) answer your question? – dbc May 02 '16 at 21:48
  • By the way, [JSON is not JavaScript](https://stackoverflow.com/questions/3975859/what-are-the-differences-between-json-and-javascript-object). Your question includes JavaScript not JSON. – dbc May 02 '16 at 22:00

0 Answers0