Automatic for the people
If the result set is empty display a message, "Catalog Id is Valid". The
addAssign method sets the
innerHTML of the
$objResponse->addAssign("validationMessage","innerHTML","Catalog Id is Valid");
If the result has rows, set the
innerHTML of the
validationMessage div to "Catalog Id is not Valid".
$objResponse->addAssign("validationMessage","innerHTML","Catalog Id is not Valid");
Next, fetch values from the result set and set the values in the input form fields. Set the
value attribute of the input form field elements with
addAssign method. For example, the
value attribute of the
journal element is set as shown below.
Also disable the submit button.
$objResponse object from the
validateCatalogId function as an XML string.
Process the Ajax response
The data specified in the
$xmlResponse object with
addAssign; method is therefore set in the input form. The
input.php script is available in resources zip.
input.php script in the Apache web server with the URL
http://localhost/input.php. Start adding a value for the Catalog Id field. An
XMLHttpRequest request is sent to the server with each addition to the text field. The input page gets updated with response from the server that contains instructions about the validity of the Catalog Id. A message is displayed (below) to verify if the Catalog Id field value is valid.
If a value is specified that is already defined in the Catalog table, a message "Catalog Id is not Valid" is displayed - as in our next screen shot.
A new catalog entry can be created by specifying a Catalog Id field that is valid and adding values to the other form fields, as shown in our final screen shot.
Ajax has various applications such as auto completion, dynamic form validation, and partial page refreshes. In this article you have learned to use Ajax with PHP with a PHP framework for Ajax. You did not have to use an
Sponsored: 2016 Cyberthreat defense report