Feeds

Xajax and PHP: JavaScript without the pain

Automatic for the people

  • alert
  • submit to reddit

Combat fraud and increase customer satisfaction

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

SANS - Survey on application security programs

More from The Register

next story
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Oh no, Joe: WinPhone users already griping over 8.1 mega-update
Hang on. Which bit of Developer Preview don't you understand?
Microsoft lobs pre-release Windows Phone 8.1 at devs who dare
App makers can load it before anyone else, but if they do they're stuck with it
Half of Twitter's 'active users' are SILENT STALKERS
Nearly 50% have NEVER tweeted a word
Internet-of-stuff startup dumps NoSQL for ... SQL?
NoSQL taste great at first but lacks proper nutrients, says startup cloud whiz
IRS boss on XP migration: 'Classic fix the airplane while you're flying it attempt'
Plus: Condoleezza Rice at Dropbox 'maybe she can find ... weapons of mass destruction'
Ditch the sync, paddle in the Streem: Upstart offers syncless sharing
Upload, delete and carry on sharing afterwards?
New Facebook phone app allows you to stalk your mates
Nearby Friends feature goes live in a few weeks
Microsoft TIER SMEAR changes app prices whether devs ask or not
Some go up, some go down, Redmond goes silent
prev story

Whitepapers

Securing web applications made simple and scalable
In this whitepaper learn how automated security testing can provide a simple and scalable way to protect your web applications.
3 Big data security analytics techniques
Applying these Big Data security analytics techniques can help you make your business safer by detecting attacks early, before significant damage is done.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Top three mobile application threats
Learn about three of the top mobile application security threats facing businesses today and recommendations on how to mitigate the risk.
Combat fraud and increase customer satisfaction
Based on their experience using HP ArcSight Enterprise Security Manager for IT security operations, Finansbank moved to HP ArcSight ESM for fraud management.