Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


The following example demonstrates an HTML5 form saving data via an Ajax API call using the POST method. The ajax call will be processed by an REST resource written in xml.


Javascript ajax to resource form.xml

Code Block
//get the form from DOM (Document object model) 
    var form = document.getElementById('x-login-form');
    form.onsubmit = function(event){
        var xhr = new XMLHttpRequest();
        var data = new FormData(form);
        //open the request'POST','http://localhost:7000/tests/v1.0/form')
        //send the form data
        //Dont submit the form.
        return false; 

On the Network

The form-data format for sending data over the network to the server.


The parameters sent in the POST request are received and replaced with their corresponding $ symbols. These $ variables must match the exact names of the POST params that are sent in the request. Here's the resource form.xml

Code Block

<?xml version="1.0" encoding="UTF-8" ?>
<Resource xmlns="" v="1.0">
    <Request method="POST">
        <Desc> Create a User </Desc>
            INSERT INTO USER (user, pass, comment) 
            values ($iuser, $xpass, $comment)

In the Database

If you query the user table, you can find the data just saved from the form.