Feeds

Xajax and PHP: JavaScript without the pain

Automatic for the people

  • alert
  • submit to reddit

HP ProLiant Gen8: Integrated lifecycle automation

Also specify in the tags of the input form that Xajax should generate any required JavaScript after an XML response has been sent back from the server.

<?php $xajax->printJavascript('./xajax');
?>

A XMLHttpRequest is initiated by a client application. In the example application, a XMLHttpRequest is initiated by the onkeyup event handler in input field catalogId.

<tr><td>Catalog Id:</td><td><input    type="text"
            size="20"  
              id="catalogId"
            name="catalogId"
    autocomplete="off"
         onkeyup="xajax_validateCatalogId(xajax.getFormValues('validationForm'));"></td>
         <td><div id="validationMessage"></div></td>
</tr>

The input field invokes the wrapper function xajax_validateCatalog with an array of form field values as a parameter. The wrapper functions send a XMLHttpReques to the server. The xajaxobject receives the XMLHttpRequest and invokes the corresponding PHP function validateCatalogId($formValues).

Process an Ajax request

Xajax provides the xajaxResponseclass to send a response to the client application. In the validateCatalogId function, create a xajaxResponse object.

$objResponse = new xajaxResponse();

The validateCatalogId function validates a Catalog Id value added in the input form. From the $formValues array retrieve the value of the catalogId field.

$catalogId=trim($formValues['catalogId']); 

Next, use the PHP Oracle extension to connect with the Oracle database and determine if a Catalog table row is defined for the catalog id value input in the input form. If the result set is empty, a Catalog table row for the catalog id value is not defined in the database table. Therefore, the Catalog Id field value added in the form is valid.

Next, we shall generate a response to be sent to the client application. A response contains one or more command messages. Some of the commonly used command messages are discussed in table below.

Command Message Description
Assign Sets the specified attribute of an element in input page with method addAssign().
Append Appends data to the specified attribute of an element in the input page with method addAppend().
Prepend Prepends data to the specified attribute of an element in the input page with method addPrepend().
Replace Replaces data in the specified attribute of an element in the input page with method addReplace().
Script Runs the specified JavaScript code with method addScript().
Alert Displays an alert box with the specified message with method addAlert().

The Power of One eBook: Top reasons to choose HP BladeSystem

More from The Register

next story
Apple fanbois SCREAM as update BRICKS their Macbook Airs
Ragegasm spills over as firmware upgrade kills machines
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
Mozilla fixes CRITICAL security holes in Firefox, urges v31 upgrade
Misc memory hazards 'could be exploited' - and guess what, one's a Javascript vuln
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Captain Kirk sets phaser to SLAUGHTER after trying new Facebook app
William Shatner less-than-impressed by Zuck's celebrity-only app
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
EU dons gloves, pokes Google's deals with Android mobe makers
El Reg cops a squint at investigatory letters
Chrome browser has been DRAINING PC batteries for YEARS
Google is only now fixing ancient, energy-sapping bug
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
Reducing security risks from open source software
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.