concept JavaScript in category php

appears as: JavaScript, JavaScript, The JavaScript
Zend Framework in Action

This is an excerpt from Manning's book Zend Framework in Action.

When you need to communicate with another application over HTTP, the most common transfer format is one of two flavors of XML: XML-RPC and SOAP. PHP5 contains excellent built-in SOAP support, and Zend Framework provides Zend_XmlRpc_Client to allow for easy processing of XML-RPC. More recently, the lightweight JSON (JavaScript Object Notation) protocol has been gaining favor, mainly due to how easy it is to process within the JavaScript of an Ajax application. Zend_Json provides a nice solution to both creating and reading JSON data.

The key component in Ajax technologies is JavaScript and the browser’s Document Object Model (DOM), which enables scripts to manipulate the web page. JavaScript is a proper programming language in its own right and has been implemented in mainstream browsers since 1995. The DOM is a standardized way of representing the elements of a web page as a tree of objects that can be manipulated by JavaScript. Within Ajax applications, this is the means by which the application dynamically changes the web page to show new information without the server’s sending new data.

JavaScript’s object model is a little different from PHP’s, and to create a class, we don’t need a class keyword; we need only a function that will act as the constructor. The rest of the class’s methods are then added to the prototype property of the constructor function, which will make them available to all instances of the class. Appendix B of Ajax in Action (by Dave Crane and Eric Pascarello) has more details if you need to refresh your knowledge of the JavaScript object model.

PHP in Action: Objects, Design, Agility

This is an excerpt from Manning's book PHP in Action: Objects, Design, Agility.

There are a huge number of tools available for web testing, both commercial and free. A fairly complete list is maintained at http://www.softwareqatest.com/qatweb1.html. It’s well worth scanning through this list, as it’s easy to end up reinventing the wheel. For this chapter, we’ll take the easy option and make use of the web tester built into SimpleTest. This tool lacks support for JavaScript, so for really complex dynamic sites, you may want to look at Selenium (http://www.openqa.org/selenium/).

In this section, we’ll start by dealing with the parts of the Front Controller in turn. We’ll look at the Web Handler and the commands, using two approaches to commands: one class per command, or multiple commands per class. Then we’ll look at some specific challenges that can occur with forms: multiple submit buttons and submits that are generated in JavaScript.

16.3.5. Generating commands with JavaScript

Another variation that sometimes occurs in web applications is when non-button elements of the page have JavaScript that will cause the form to submit when the control is changed. An example would be a <select> menu like this one:

<select name="module" onChange="this.form.submit();">
  <option>News</option>
  <option>Discussion</option>
  <option>Calendar</option>
</select>

Since this example already uses JavaScript, it’s safe to use more JavaScript. That makes it easy to add a command name to the HTTP request: