Section A.8. Use a JSON parser


A.8. Use a JSON parser

If you're concerned about security with JSON, you may want to use a JSON parser, and avoid using eval() in your JavaScript functions.

Where to get it: http://www.json.org/js.html

How to use it:

You'll have to reference the JSON.js file you download from the json.org web site. using <script> tags in your HTML.

 function updatePage() {    if (request.readyState == 4) {      if (request.status == 200) {JSON.parse() takes a text response from the server and converts it into an object.                var jsonData = JSON.parse(request.responseText); A JSON parser will only accept string input... anything else is kicked out. No security risk! Like PROJECT: CHAOS!      // Get the updated totals from the XML response    var totalBoards = jsonData.totals[0].boardsSold + 




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net