Book Image

jQuery 2.0 Development Cookbook

By : Leon Revill
Book Image

jQuery 2.0 Development Cookbook

By: Leon Revill

Overview of this book

Table of Contents (17 chapters)
jQuery 2.0 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Processing JSON data


JavaScript Object Notation (JSON) provides web developers with a clean and efficient way to encode data. JSON is a widely adopted format. It simplifies data processing and manipulation. To read more about why you should use JSON, visit http://www.revillweb.com/why-use-json/.

Getting ready

Ensure that your web server is running and you have access to the web root where you can save/upload the files that you will create as part of this recipe.

How to do it…

Learn how to use JSON-formatted data with JavaScript by performing the following steps:

  1. Create a PHP file named request-3.php and save it to the web root of your web server. Use the following PHP code to create and output a list of names as JSON data:

    <?php
      //Create an array of people
      $people = array(
        1 => array(
          "firstname" => "Luke",
          "lastname" => "Skywalker"
        ),
        2 => array(
          "firstname" => "Darth",
          "lastname" => "Vader"
        ),
        3 => array(
          "firstname...