AJAX and Fetch - Using JavaScript
Lab
Reading
- Beginning JavaScript - chapter 12 - JSON
- Beginning JavaScript - chapter 14 - AJAX
Homework
- Part 1.
- Create a PHP or Python program that received a parameter via GET (i.e. using the query_string)
- Parameter examples: student_id=5 or cust_name=sultan or product=hammer
- Program should retrieve data based on the requested parameter from your database table(s)
- Program parameter could be a partial value (example: cust_name=sul)
- Program should retrieve the requested data, and respond using JSON format
- Test your program directly thru a browser (example: https://absolute_url?cust_name=sul)
- You should receive the program JSON output on a brand new browser page
- Part 2.
- Create a web page containing JavaScript code
- Web page should have a form that allows the capture of parameter (example customer name)
- Create an event listener that is triggered upon every character entered in the form input field
- Event listener should call the PHP/Python program and pass it the partial characters entered in the form field
- Use AJAX or Fetch to fetch the data from the server side. URL example would be https://absolute_url?cust_name=sul
- When JavaScript receives the JSON output from the server program, display accordingly
- Allow the user to continue typing in the form input field
- Upon further character entry in the input field, repeat the process
View Notes