Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
54 views

PHP AJAX Programming - Phppot

This document discusses PHP AJAX programming. It defines AJAX as a method to request server-side scripts via JavaScript. The request is sent to a PHP file which processes it and sends a response without refreshing the page. The document provides an example using XMLHttpRequest to send a login request to a PHP script, which checks the credentials in a MySQL database and returns the authentication status. It includes code for the JavaScript function, PHP login script, and HTML login form.

Uploaded by

Asma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

PHP AJAX Programming - Phppot

This document discusses PHP AJAX programming. It defines AJAX as a method to request server-side scripts via JavaScript. The request is sent to a PHP file which processes it and sends a response without refreshing the page. The document provides an example using XMLHttpRequest to send a login request to a PHP script, which checks the credentials in a MySQL database and returns the authentication status. It includes code for the JavaScript function, PHP login script, and HTML login form.

Uploaded by

Asma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

04/01/2021 PHP AJAX Programming - Phppot

helping build websites Shop Services Testimonials Blog About Con

eCommerce PHP AJAX Programming Hi, I’m Vincy. I help build websites
Components Last modified on April 6th, 2017. and I’m available for freelance work.
Files
AJAX can be expanded as Asynchronous Javascript and XML and it is a vincy@phppot.com
UI method to request a server side script to execute via javascript. This request is
Performance generated in a Javascript function and sent to a PHP file. In server side, PHP
Contact Form - Iris
file it receives and processes the request passed through an AJAX call and
Framework
send a response. The client-server communication will be done in
PHP an asynchronous way. After getting a response from the PHP file, we can update
Learn PHP a particular component of a web page and avoid page refresh.
PHP Introduction
AJAX can be implemented by using various libraries and API. In this tutorial, I
PHP Basics
am using XMLHTTPRequest API to send an AJAX request for executing PHP
Contact Form
login script. After getting the response from the PHP, the AJAX code checks the
Comments System
status and show authentication result in the web page without refreshing it.
Types, Variables &
Operators
PHP Strings
PHP Arrays
PHP Functions
PHP OOPS
“From initial enquiry to wrap up, Vincy
PHP Forms
produced technically astute assets which
Advanced enabled our team back in The Netherland
PHP AJAX deliver a rock-solid product ...” read more
Country-State-City
Example: Cascading Sal Souza, Ofamfa, The Netherlands
jQuery AJAX
Dependent Dropdown
in PHP
Load Dependent
Dropdown on Multi-
Select using PHP and
jQuery
AJAX Based Login
Registration System
with jQuery Lightbox
Create AJAX-Based
PHP Event
Login Form with AJAX Button Handler
Management System
with Bootstrap The following code shows a login form with the User Name and the Password
How to Create fields. On clicking the Login button, it calls a Javascript AJAX function. This
Facebook Like Infinite
Scroll Pagination using function will send the login field values to PHP to process user authentication. It
PHP and jQuery contains a target DIV container where authentication results will be shown to the
Facebook Like Header user by AJAX function without refreshing login page.
Notification in PHP
Sorting MySQL Row <div id="output">
Order using jQuery <div id="messageBoxId"></div>
AJAX Pagination with <form action="" method="post" id="frmLogin">
PHP <div class="field-group">
<div><label for="login">Username</label></div>
Change Order of <div><input name="userName" id="userName" type="text" class=
Images in Photo </div>
Gallery with Drag and <div class="field-group">
Drop using PHP AJAX <div><label for="password">Password</label></div>
PHP AJAX <div><input name="password" id="password" type="password" cl
Programming </div>
<div class="field-group">
PHP Star Rating <div><input type="button" name="login" value="Login" class="
System with JavaScript </div>
</form>
Events Display using
</div>
PHP AJAX with CLNDR
Calendar Plugin
RESTful API
PHP Databases
Sending Login Request via Javascript AJAX
PHP Sessions and
Cookies Function
Error and Exception
Handling In this Javascript function we create AJAX login request by using
File Upload XMLHttpRequest instance. Since old browsers are not supporting this API, we
Files and Directories can create ActiveXObject. This function sends user’s login details to login.php
PHP Date Time as the “GET” requests. If the user is authenticated successfully, then this
PHP XML function will show welcome screen. Otherwise, an error message will be shown
PHP Code Samples on top of the login form. All these changes will be made by the AJAX instead of
Library reloading the page.
More PHP

https://phppot.com/php/ajax-programming-with-php/ 1/4
04/01/2021 PHP AJAX Programming - Phppot
PHP Freelancer <script>
function callLogin(){
var userName = document.getElementById("userName").value;
var password = document.getElementById("password").value;
xmlHttpRequest=new XMLHttpRequest();
// For Older browsers
// xmlHttpRequest=new ActiveXObject("MSXML2.XmlHttp");
xmlHttpRequest.onreadystatechange=function() {
if (xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200)
var response = xmlHttpRequest.responseText;
if(response > 0) {
var welcome_message = '<p class="welcome-message">Welcom
document.getElementById("output").innerHTML = welcome_me
} else {
document.getElementById("messageBoxId").innerHTML="Inval
document.getElementById("messageBoxId").className="error
}
}
}
xmlHttpRequest.open("GET","login.php?userName="+userName+"&password=
xmlHttpRequest.send();
}
</script>

PHP Login Script with MySQL.


The following PHP code receives AJAX requests and process authentication. It
searches user database for the login details passed by the AJAX call. If a match
is found, then it will return true as a response.

<?php
if(count($_GET)>0) {
$conn = mysqli_connect("localhost","root","","blog_samples");
$result = mysqli_query($conn,"SELECT * FROM users WHERE userName
"SELECT * FROM users WHERE userName='" . $_GET["userName"] . "'
$count = mysqli_num_rows($result);
print $count;
mysqli_close($conn);
}
?>

download

Comments to “PHP AJAX Programming”

Muralidhar
July 25, 2013 at 8:22 am

Nice Explanation Vincy…Thank you.

Reply

Vincy
July 26, 2013 at 5:41 am

Welcome.

Reply

Vladimir
August 17, 2013 at 9:17 pm

God bless you!

Reply

Arvind
October 30, 2013 at 6:54 pm

Hello Vincy

Nice site, it is not comment but a suggesion. At the you are displaying facebook
and twitter but you forgot to set your facebook and twitter page.

https://phppot.com/php/ajax-programming-with-php/ 2/4
04/01/2021 PHP AJAX Programming - Phppot
Please set it……

Reply

ken
May 22, 2014 at 10:28 pm

Nice!!, I have a question though. After authenticating using ajax, how do you go
about managing the session using php.

Reply

krishna chaitanya
July 10, 2014 at 10:48 pm

Informative.
thank you.

Reply

yash
July 5, 2019 at 1:22 pm

nice work
cool

Reply

Vincy
July 5, 2019 at 3:53 pm

Thank you Yash.

Reply

Sumant kumar
July 30, 2019 at 4:08 pm

nice work.

Reply

Vincy
June 25, 2020 at 12:29 pm

Thank you Sumant.

Reply

Leave a Reply

Comment

Name *

Email *

https://phppot.com/php/ajax-programming-with-php/ 3/4
04/01/2021 PHP AJAX Programming - Phppot

Post Comment

Popular Articles
★ Create AJAX-Based PHP Event Management System with Bootstrap
★ PHP Star Rating System with JavaScript
★ AJAX Based Login Registration System with jQuery Lightbox

Search articles

↑ Back to Top

Looking for a freelance web developer?


Do you want to build a modern, lightweight, responsive website and launch quickly? Contact Me

Blog subscription:

Enter your email here Subscribe

Shop

FAQ Support Policy Refund Policy Licenses


Terms of Service Privacy Policy Cookie Policy © 2020 Phppot

https://phppot.com/php/ajax-programming-with-php/ 4/4

You might also like