Cancels the current HTTP request. Returns null if readyState is other than 3 or 4. Invoking the open method sets the readyState property to 1. Boolean value for asynch specifies if HTTP request is asynchronous; Boolean value parameter is not required to be specified and default value is true.
Username and password are specified for server side authentication and are optional. The data sent with send method is optional and may be null.
The send method is synchronous or asynchronous based on the value of the asynch argument in the open method. If synchronous, the method does not return until the entire response is received. If asynchronous, the method returns immediately.
The readyState property is set to 2 after invoking the send method. The readyState property is set to 4 when the request has completed loading. In the project, add a JSP file, input.
In the Error Page Options frame select default settings and click on Next. In Tag libraries frame, select default settings and click on Next. The JSP provides the client side of the Ajax application. Similarly, add JSPs, catalog. Specifying Servlet Mapping In Servlet Parameters frame, specify any servlet parameters, if required, and click on Finish.
The resulting Ajax application structure is shown in Figure 3. Adding Project Libraries The Ajax application in this article retrieves data and updates data in a Oracle Database 10g Express Edition Oracle's free developer edition table. Download and nstall Oracle Database XE, including the sample schemas, and create a database instance. Create a database table, Catalog, with the SQL script below.
The Create Database Connection wizard gets started. In the Authentication frame, specify Username and Password, and click on Next. Specify the SID and click on Next. In the Test frame, click on Test Connection button. Data added to the HTML form is sent asynchronously to the server.
In the client application, the response from the server is processed and a message is output about the validity of the data added.
In the example application, an input form is used to create a catalog entry that is sent to the server and updated in the database in a server side Servlet. You will probably be interested in ascertaining if a catalog Id specified in the input form is not already taken in the catalog database. As the client specifies the catalog Id field, a XMLHttpRequest is sent to the server with each modification in the input field.
If the ResultSet object is empty, the catalogId field value is not defined in the database table Catalog, therefore the catalogId field value is valid. If the ResultSet object has data, the catalogId value is already defined in the database, therefore, the catalogId field value is not valid. If a catalog entry is already defined for the catalogId value, include the field values of the different fields in the input form in the XML DOM object.
Click here to view FormValidationServlet. In the processResponse function, obtain the value for the responseXML property. Enable the submit button in the input form. Disable the submit button, and set the values of the other input fields. Next, run the Ajax application in JDeveloper Right-click on the input.
Running the Ajax Application The input form gets displayed. Start adding data to Catalog Id field. A catalog entry for the specified field values gets added to the database. Conclusion As you've seen here, the Ajax technique provides dynamic validation of data added to an input form using the XMLHttpRequest object. For example, the server side application may be a PHP script instead of a servlet.
Deepak Vohra dvohra09 yahoo.