Note that there are some explanatory texts on larger screens.

plurals
  1. POAm I not returning this JSON string correctly?
    primarykey
    data
    text
    <p>I'm trying to grab some values from the database using AJAX, but every time I check firebug, I see the html copy instead.</p> <pre><code> function foo() { $.ajax({ type: "POST", url: "cssAttempt3.aspx/ConvertDataTabletoString", data: {}, dataType: 'json', success: function (response) { console.log(result); //I have tried a bunch of things here. //console.log(response, response[0], response[0].value, //JSON.parse('&lt;%=ConvertDataTabletoString() %&gt;'), JSON.parse(response), JSON.stringify(response), and the list goes on. //Every single time, Firebug shoots back the html document. //Nothing really stands out in this html document. No errors. //But time to time, Firebug will say unidentified character //JSON.parse: unexpected character //Line 4 //Which can't be right, I'm using Google's jQuery and the console.log below is parsed correctly. //If you look up there, result and response are two different things //But Firebug won't report any error even when I compile that. //I've even typed alert("ASDFSAOF") just to see what happens. Nothing. //I haven't seen "Fail" either. }, failure: function () { console.log("Fail"); } }); }; foo(); console.log(JSON.parse('&lt;%=ConvertDataTabletoString() %&gt;')); //This, which has nothing to do with AJAX, works okay. //I've taken from the html document &lt;/script&gt; </code></pre> <p>I reedited this, because I do not think it's the JSON. My apologies for leading everyone that way.</p> <pre><code>using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Runtime.Serialization; public partial class cssAttempt3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } // This method is used to convert datatable to json string [System.Web.Services.WebMethod] public static string ConvertDataTabletoString() { DataTable dt = new DataTable(); using (SqlConnection con = new SqlConnection(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=personnet;Integrated Security=Yes;")) { using (SqlCommand cmd = new SqlCommand(@"SELECT TOP 200 * FROM personnet.dbo.accordionTest", con)) { con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); List&lt;Dictionary&lt;string, object&gt;&gt; rows = new List&lt;Dictionary&lt;string, object&gt;&gt;(); Dictionary&lt;string, object&gt; row; foreach (DataRow dr in dt.Rows) { row = new Dictionary&lt;string, object&gt;(); foreach (DataColumn col in dt.Columns) { row.Add(col.ColumnName, dr[col]); } rows.Add(row); } return serializer.Serialize(rows); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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