Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Update</strong>: See Anthony Grist's comment on your question, I missed the fact that your JSON is invalid. Since he hasn't posted an answer, I'll pick it up.</p> <p>Your <a href="http://json.org" rel="nofollow">JSON</a> is invalid because you're returning two separate arrays, this one:</p> <pre><code>[{"v":"233","pv":"1.83","avd":"00:01:58","nv":"82.83%","br":"75.11%"}, {"v":"17","pv":"3.65","avd":"00:08:31","nv":"70.59%","br":"58.82%"}, {"v":"9","pv":"2.22","avd":"00:01:51","nv":"0.00%","br":"44.44%"}] </code></pre> <p>and this one:</p> <pre><code>[{"date":"2013-02-01","visits":63}, {"date":"2013-02-02","visits":30}] </code></pre> <p>You can't do that, because the top level of a JSON document must be <strong>one</strong> thing (an object or an array).</p> <p>You could return an object with properties for each array:</p> <pre><code>{ "vdata": [{"v":"233","pv":"1.83","avd":"00:01:58","nv":"82.83%","br":"75.11%"}, {"v":"17","pv":"3.65","avd":"00:08:31","nv":"70.59%","br":"58.82%"}, {"v":"9","pv":"2.22","avd":"00:01:51","nv":"0.00%","br":"44.44%"} ], "datedata": [{"date":"2013-02-01","visits":63}, {"date":"2013-02-02","visits":30} ] } </code></pre> <p>After parsing (see below), you can access that data like this:</p> <pre><code>console.log(data.vdata[0].v); // "233" console.log(data.datedata[0].date); // "2013-02-01" </code></pre> <p>Or an array with two slots, with each slot having one of your arrays in it:</p> <pre><code>[ [{"v":"233","pv":"1.83","avd":"00:01:58","nv":"82.83%","br":"75.11%"}, {"v":"17","pv":"3.65","avd":"00:08:31","nv":"70.59%","br":"58.82%"}, {"v":"9","pv":"2.22","avd":"00:01:51","nv":"0.00%","br":"44.44%"} ], [{"date":"2013-02-01","visits":63}, {"date":"2013-02-02","visits":30} ] ] </code></pre> <p>After parsing (see below), you can access that data like this:</p> <pre><code>console.log(data[0][0].v); // "233" console.log(data[1][0].date); // "2013-02-01" </code></pre> <p>Personally, I prefer using an object, since then it's clear which array I'm accessing.</p> <hr> <p>Original answer:</p> <p>jQuery will parse the JSON into an object for you and pass that to the <code>success</code> function, which you can then access just like any other object. In your case, the top level is an array. So:</p> <pre><code>$.ajax({ url: url, type: 'POST', dataType:"json", async: false, success: function(data) { // Use the line from above that suits the way // you updated your JSON structure } }); </code></pre> <hr> <p>Side note: <code>async: false</code> is deprecated and will be removed at some point. It's generally not a good idea to do synchronous ajax requests, it tends to lock up the UI of the browser during the request. Instead, just structure your code to continue processing when the <code>success</code> callback is triggered.</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