Note that there are some explanatory texts on larger screens.

plurals
  1. PObuilding dynamic table from json serialized list object
    primarykey
    data
    text
    <p>I'm trying to get a serialized json list via ajax and create dynamic table in a html jquery mobile page. the list comes from a sql database in code behind. I just don't know if I'm returing the json object right, and how to access it from the ajax success function.</p> <p>My goal is to create dynamically a table of all the members in the html.</p> <p><strong>I created a Member class:</strong></p> <pre><code>public class Member { public Member() { // // TODO: Add constructor logic here // } public String fName { set; get; } public String lName { set; get; } } </code></pre> <p><strong>This is my function to return the member list in code behind: (written in a class that connects with the sql)</strong></p> <pre><code>public List&lt;Member&gt; return_member_list() { List&lt;Member&gt; member_list = new List&lt;Member&gt;(); String fName; String lName; SqlConnection user_con = connect("ActConString"); SqlCommand user_command = create_command(user_con, "select m_first_name, m_last_name from member"); SqlDataReader rdr = user_command.ExecuteReader(); while (rdr.Read()) { Member m1 = new Member(); fName = Convert.ToString(rdr["m_first_name"]); lName = rdr["m_last_name"].ToString(); m1.fName = fName; m1.lName = lName; member_list.Add(m1); } rdr.Close(); user_con.Close(); return member_list; } </code></pre> <p><strong>then I use an aspx page web method to return the list serialized:</strong></p> <pre><code> [WebMethod] public static String return_member_list() { dbservices db1 = new dbservices(); List&lt;Member&gt; member_list = db1.return_member_list(); var jsonSerialiser = new JavaScriptSerializer(); var json = jsonSerialiser.Serialize(member_list); return json; } </code></pre> <p><strong>and the ajax:</strong></p> <pre><code> $(document).ready(function () { $.ajax({ type: "POST", url: "getdata.aspx/return_member_list", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (res) { //this is where I need help }, error: function (res, msg, code) { // log the error to the console alert("The following error occured: " + msg + " " + code); } //error }); }); </code></pre> <p>I'd appriciate help with creating the table dynamically as well : )</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload