Feeds

Xajax and PHP: JavaScript without the pain

Automatic for the people

  • alert
  • submit to reddit

Boost IT visibility and business value

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().

Boost IT visibility and business value

More from The Register

next story
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
KDE releases ice-cream coloured Plasma 5 just in time for summer
Melty but refreshing - popular rival to Mint's Cinnamon's still a work in progress
Leaked Windows Phone 8.1 Update specs tease details of Nokia's next mobes
New screen sizes, dual SIMs, voice over LTE, and more
Secure microkernel that uses maths to be 'bug free' goes open source
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
Mozilla keeps its Beard, hopes anti-gay marriage troubles are now over
Plenty on new CEO's todo list – starting with Firefox's slipping grasp
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
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
prev story

Whitepapers

Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Backing up Big Data
Solving backup challenges and “protect everything from everywhere,” as we move into the era of big data management and the adoption of BYOD.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Why and how to choose the right cloud vendor
The benefits of cloud-based storage in your processes. Eliminate onsite, disk-based backup and archiving in favor of cloud-based data protection.