0% found this document useful (0 votes)
58 views

Aim:-To Study AJAX and PHP For Form Validation. Theory Ajax

This document discusses using AJAX and PHP for form validation. It provides details on AJAX and how it allows asynchronous data exchange in the background without page reloads using XMLHttpRequest. It also covers PHP functions like require_once, $_GET, and mysql_query that can be used to retrieve and process form data from a server database. The goal is to validate user form inputs on the browser side to reduce server loads and provide quick feedback to users without full page reloads for a better interactive experience.

Uploaded by

Amit Gundewar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Aim:-To Study AJAX and PHP For Form Validation. Theory Ajax

This document discusses using AJAX and PHP for form validation. It provides details on AJAX and how it allows asynchronous data exchange in the background without page reloads using XMLHttpRequest. It also covers PHP functions like require_once, $_GET, and mysql_query that can be used to retrieve and process form data from a server database. The goal is to validate user form inputs on the browser side to reduce server loads and provide quick feedback to users without full page reloads for a better interactive experience.

Uploaded by

Amit Gundewar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Aim :- To study AJAX and PHP for form validation.

Theory :

AJAX:
1. Ajax (shorthand for Asynchronous JavaScript and XML) is a group of
interrelated web development techniques used on the client-side to create
interactive web applications. With Ajax, web applications can retrieve data
from the server asynchronously in the background without interfering with
the display and behavior of the existing page. The use of Ajax techniques
has led to an increase in interactive or dynamic interfaces on web pages.
Data is usually retrieved using the XMLHttpRequest object. Despite the
name, the use of XML is not actually required, nor do the requests need to
be asynchronous.
2. Like DHTML , Ajax is not a technology in itself, but a group of
technologies. Ajax uses a combination of HTML and CSS to mark up and
style information. The DOM is accessed with JavaScript to dynamically
display, and to allow the user to interact with the information presented.
JavaScript and the XMLHttpRequest object provide a method for
exchanging data asynchronously between browser and server to avoid full
page reloads.

XMLHTTP:
1. XMLHTTP was first introduced as a Microsoft ActiveX control in Microsoft
Internet Explorer 5. Over time, this object has been implemented by other
browsing platforms and is the cornerstone of Web applications based on
Asynchronous JavaScript and XML (AJAX).
2. The XMLHTTP object enables the browser to send and receive
asynchronous, out-of-band HTTP requests to the Web server, which
responds with XML. The response can be manipulated with client-side script
or transformed with Extensible Style sheet Language Transformations
(XSLT). XMLHTTP makes it possible to create responsive Web
applications that do not have to refresh the entire page to display new data.
3. XMLHTTP can be thought of as an XML-based response/request protocol,
which allows us to send text/xml to a remote server. That server processes
the request, and in-turn, returns either a text/XML data stream or a binary
stream of characters.

4. window.XMLHttpRequest: The XMLHttpRequest object is used to


exchange data with a server behind the scenes.
It does following things:
1. Update a web page without reloading the page
2. Request data from a server after the page has loaded
3. Receive data from a server after the page has loaded
4. Send data to a server in the background

JS functions:
1. document.getElementById: Returns the element whose ID is specified. If
more than one element is found, getElementById returns the first object in
the collection.
2. innerHTML: The innerHTML property sets or returns the inner HTML of an
element.
AJAX Functions:

1. Onreadystatechange: When a request to a server is sent, we want to perform


some actions based on the response.The onreadystatechange event is
triggered every time the readyState changes. The readyState property holds
the status of the XMLHttpRequest. It stores a function (or the name of a
function) to be called automatically each time the readyState property
changes.
2. readyState: Holds the status of the XMLHttpRequest. Changes from 0 to
4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready.
3. Status: 200: "OK"
404: Page not found

PHP Functions:
1. require_once: The require once() statement is identical to require() except PHP will
check if the file has already been included, and if so, not include it again.
2. $_GET: The built-in $_GET function is used to collect values in a form with
method="get".Information sent from a form with the GET method is visible to everyone
(it will be displayed in the browser's address bar) and has limits on the amount of
information to send (max. 100 characters).
3. die(): It is executed if connection fails.
4. mysql_num_rows(): The mysql_num_rows() function returns the number of rows in a
recordset . This function returns FALSE on failure

5. echo: The echo() function outputs one or more strings. The echo() function is not
actually a function, so it is not required to use parentheses with it. However, if we want
to pass more than one parameter to echo(), using parentheses will generate a parse error.
6. mysql_query: The mysql_query() function executes a query on a MySQL database.This
function returns the query handle for SELECT queries, TRUE/FALSE for other queries, or FALSE
on failure.
Applications and Implications :

There are various applications of using AJAX for creating web pages. It allows
web pages to be updated asynchronously without needing it to be reloaded. It
exchanges small part of data with web server. This all process is done behind the
scene. The main power of AJAX lies in creating XMLHttpRequest object. This
object is responsible for dynamic updates without reloading web pages.
AJAX can be used for interactive communication with XML file, with databases.
Form validation is important process as it avoids wrong information gathering
and storing it in databases. User input should be validated on the browser
whenever possible. This reduces load in server. At the same time we have to make
sure that user sensitive information like passwords should not be validated on
client side.
In ecommerce scenario form validation is important as it will avoid wrong
information from being entered. So it will help to understand customer correctly
and effectively. As it avoids page reloading each time user enters information and
moves to next field at that instant only previous field is checked so user feels it
very interactive. Quick reponse can be given.
Conclusion :

You might also like