JSON Programming Lecture (11) - Review - PDF
Document Details
Uploaded by Deleted User
Idris alhassan mohammed altom
Tags
Related
- Lecture 1 - Course Overview, a Cloud App Example PDF
- BCA Web Technology Exam November 2022 PDF
- Ajax PDF
- Closures and DOM in JavaScript PDF
- BSc (Hons) Software Engineering - Web Service Development Past Paper PDF - University of Technology, Mauritius 2024
- Handling JSON Data in Python - Advanced Concepts PDF
Summary
This document is a lecture on JSON programming, specifically focusing on how PHP interacts with databases using JSON. Examples of converting objects to JSON and retrieving data from PHP files are demonstrated.
Full Transcript
Lecture (11)- JSON (2) By : Idris alhassan mohammed altom JSON PHP A common use of JSON is to read data from a web server, and display the data in a web page. PHP has some built-in functions to handle JSON. Objects in PHP can be converted into JSON by using the PHP funct...
Lecture (11)- JSON (2) By : Idris alhassan mohammed altom JSON PHP A common use of JSON is to read data from a web server, and display the data in a web page. PHP has some built-in functions to handle JSON. Objects in PHP can be converted into JSON by using the PHP function json_encode() [email protected] ‫إدريس‬ ‫الØسن Ù…Øمد التوم‬ Converted Objects into JSON Out Put : { " bookTitle":" PHP5","auther":"Idris","price":500} [email protected] ‫إدريس الØسن‬ ‫مØمد التوم‬ Get data as JSON from a PHP file var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myObj = JSON.parse(this.responseText); document.getElementById("demo").innerHTML = myObj.bookTitle; } }; xmlhttp.open("GET", "demo_file.php", true); xmlhttp.send(); [email protected] ‫إدريس الØسن‬ ‫مØمد التوم‬ PHP Database PHP is a server side programming language, and should be used for operations that can only be performed by a server, like accessing a database. Imagine you have a database (bookshop)on the server, containing bookdata. You want to make a request to the server where you ask for the first 10 records in the " bookdata " table [email protected] ‫إدريس‬ ‫الØسن Ù…Øمد التوم‬ Use JSON.stringify() to convert the JavaScript object into JSON eg:id="demo">