PHP and Ajax
PHP and Ajax
Eman Gumayagay
What is AJAX
o Eg: http://localhost/phpmyadmin
WHAT is HTTPS?
o Eg: https://facebook.com/profile.php
HTTP Methods: GET
Best for:
✅ Fetching data
✅ Search queries
✅ Simple requests
HTTP Methods: GET
Best for:
✅ Fetching data
✅ Search queries
✅ Simple requests
HTTP Methods: POST
Best for:
✅ Submitting forms
✅ Secure data transfer
✅ Large data submission
GET vs POST
GET vs POST
Simple PHP & AJAX Example: GET
o Auto-Saving Forms
YEYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY!!!!!!!!!!!!!
Create Database
Create new
Database:
phpmyadmin
Create Users Table
Create new
Table: users
Create Columns Table
On your File Explorer, create your folder inside, htdocs at XAMPP, after that open
your folder at VS Code
Include your
connection to you
main File:
index.php
Create UI: HTML
Add JavaScript
scripts, to integrate
with PHP, insert.php
Were sending
query string to
the server
Registration
In your insert.php,
Create a query
that will insert a
user if it doesn’t
exists yet! For
added security.
TEST
Now if we test at
the browser, after
submitting we can
see a alert notif,
and the data is
being inserted on
the background.
FETCHING in Background
Use GET
XMLHttpRequest to
request to server;
Add background
functionalities that
gets user, and
display to table.
TEST
Test again,
After registering
it will update
our table.
DISPLAY
As we can see
here, when the
page is loaded, the
users isn’t loading
yet, so we need to
display them first.
DISPLAY using Fetch
So include your
fetch.php inside the
tbody, it will run
again the fetch and
return it’s value,
and then appended
to the table.
YEYYYYYYYYYYYYYYYYYYYY
HAPPY CODING!