Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From your examples and comments, it's possible your JSON isn't valid. You can validate your output at <a href="http://jsonlint.com/" rel="nofollow">JSONLint</a>. It'd really help if you showed how you were creating your JSON feed at <code>cssAttempt3.aspx/ConvertDataTabletoString</code>.</p> <p>Another problem is that you are using <code>JSON.parse</code> instead of <code>JSON.stringify</code>. </p> <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse?redirectlocale=en-US&amp;redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FJSON%2Fparse" rel="nofollow">JSON.parse</a> parses a <em>string</em> as JSON.</p> <p>The opposite, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify" rel="nofollow">JSON.stringify</a> accepts a value to convert to a JSON string. Your value (<code>response</code>) is already JSON.</p> <pre><code>function foo() { $.ajax({ type: 'POST', url: 'cssAttempt3.aspx/ConvertDataTabletoString', dataType: 'json', contentType: "application/json; charset=utf-8", success: function (response) { var t = JSON.stringify(response); var o = JSON.parse(t); //now this should work. Turns it back into what you get from url response. console.log(t); }, failure: function () { console.log("Fail"); }, error: function (jqXHR,textStatus,errorThrown) { console.log(errorThrown); //...its possibly not even JSON response at all! } }); } </code></pre> <p>As a side not, a more efficient way to create your JSON is is with an ASHX handler... and will only take minor modifications to your code:</p> <p>Add <code>[DataContract]</code> and <code>[DataMember]</code> to your class (you need a reference to <code>System.Runtime.Serialization</code> for this to work):</p> <pre><code>[DataContract] public class MyDataTableClass { [DataMember] private string pro; [DataMember] private string sn; [DataMember] private string po; //etc </code></pre> <p>And then make the ASHX (Right-click your project -> Add New Item -> Generic Handler):</p> <pre><code>public class ConvertDataTabletoString: IHttpHandler { public void ProcessRequest(HttpContext context) { List&lt;MyDataTableClass&gt; m = //populate MemoryStream stream = new MemoryStream(); DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(List&lt;MyDataTableClass&gt;)); s.WriteObject(stream, m); stream.Position = 0; StreamReader sr = new StreamReader(stream); context.Response.ContentType = "application/json"; context.Response.Write(sr.ReadToEnd()); } public bool IsReusable { get { return false; } } } </code></pre> <p>then just update your url: <code>url: 'ConvertDataTabletoString.ashx',</code></p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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