arrays - Target inline JSON using jQuery .getJSON or similar method -


i attempting data inline array wrapped in <script> tag using jquery's .getjson method. far reading in documentation (http://api.jquery.com/jquery.getjson/), .getjson requires url , external file call from.

$.getjson('items.js', function(data) {});

how use either method or 1 target inline array (without external file), such 1 below:

  <script type="application/json">       {     "items": {         "blue": {           "a": "a",           "b": "b",           "c": "c"         }      }    }   </script> 

thanks!

you can't put json in script tag, has valid javascript statements. assign json variable name:

<script> var data = {     "items": {         "blue": {           "a": "a",           "b": "b",           "c": "c"         }      } }; <script> 

then rest of code can use data access value.


Comments