Feeds

Xajax and PHP: JavaScript without the pain

Automatic for the people

  • alert
  • submit to reddit

Providing a secure and efficient Helpdesk

If the result set is empty display a message, "Catalog Id is Valid". The addAssign method sets the innerHTML of the validationMessage div.

$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.

$objResponse->addAssign("journal","value",$journal);

Also disable the submit button.

$objResponse->addAssign("submitForm","disabled",true);

Return the $objResponse object from the validateCatalogId function as an XML string.

return $objResponse->getXML();

Process the Ajax response

The XML response is sent to the xajax processor, which sends the XML response to the xajax’s JavaScript message pump. The message pump parses the XML instructions and sets the elements in the input page.

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.

Run the 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.

Validating Input Field.

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.

Catalog Id not Valid.

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.

Catalog Id Valid.

Finally

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 XMLHttpRequest object to open and send an Ajax request and process the Ajax response. Xajax generates the required JavaScript, thus, facilitating the development of an Ajax/PHP application. ®

Secure remote control for conventional and virtual desktops

More from The Register

next story
Microsoft WINDOWS 10: Seven ATE Nine. Or Eight did really
Windows NEIN skipped, tech preview due out on Wednesday
Business is back, baby! Hasta la VISTA, Win 8... Oh, yeah, Windows 9
Forget touchscreen millennials, Microsoft goes for mouse crowd
Apple: SO sorry for the iOS 8.0.1 UPDATE BUNGLE HORROR
Apple kills 'upgrade'. Hey, Microsoft. You sure you want to be like these guys?
ARM gives Internet of Things a piece of its mind – the Cortex-M7
32-bit core packs some DSP for VIP IoT CPU LOL
Microsoft on the Threshold of a new name for Windows next week
Rebranded OS reportedly set to be flung open by Redmond
Lotus Notes inventor Ozzie invents app to talk to people on your phone
Imagine that. Startup floats with voice collab app for Win iPhone
'Google is NOT the gatekeeper to the web, as some claim'
Plus: 'Pretty sure iOS 8.0.2 will just turn the iPhone into a fax machine'
prev story

Whitepapers

Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Storage capacity and performance optimization at Mizuno USA
Mizuno USA turn to Tegile storage technology to solve both their SAN and backup issues.
The next step in data security
With recent increased privacy concerns and computers becoming more powerful, the chance of hackers being able to crack smaller-sized RSA keys increases.
Security for virtualized datacentres
Legacy security solutions are inefficient due to the architectural differences between physical and virtual environments.
A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.