Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
JavaScript and JSON Essentials

You're reading from   JavaScript and JSON Essentials If you fancy a less verbose data format than CSV or XML, then JSON could be for you. This tutorial will teach you about using JSON with JavaScript for effective local storage or Internet transfers.

Arrow left icon
Product type Paperback
Published in Oct 2013
Publisher Packt
ISBN-13 9781783286034
Length 120 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sai S Sriparasa Sai S Sriparasa
Author Profile Icon Sai S Sriparasa
Sai S Sriparasa
Arrow right icon
View More author details
Toc

Hosting JSON


In this section, we will be creating a PHP script that will allow us to send a JSON feedback to the user upon a successful request. Let's take a look at the index.php file, which accomplishes this task:

In this PHP script, we have created a basic students array and are generating the JSON feed for that array. The students array contains basic student information, such as the first name, last name, student ID, and the classes that the student has enrolled.

This file has to be placed in the www folder, and it should be on the same level as the default index.html file that comes with the LAMP installation. Refer to the folder structure in the following screenshot:

Now that our index.php is in the document root folder, we can load this file using our web server. To access this file via our Apache web server, navigate to http://localhost/index.php.

As shown in the preceding screenshot, when the file is run using the Apache web server, the server takes the request, parses the PHP code...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image