XINS - AJAX Example 1
Description
This page is a demo that shows you how easy it is to use XINS in combination with AJAX.
This example requires the myproject API to run on your computer.
To run the myproject API, go to the demo\xins-project directory and execute xins run-myproject.
Form
A call is done to the API when you change the gender or lost the focus of the text field.
Answer:
Technical explanations
- The form is a HTML form where the Javascript method callMyFunction() is called
on the events onChange for the "Gender" combo box and the onChange event
for the "Last name" text field.
- The callMyFunction() method checks that the name has at least 2 characters
and then call the loadXMLDoc(URL) method with the URL pointing to the MyFunction
method of the XINS API.
- The loadXMLDoc(URL) method call the XINS API and return the result in the
processStateChange() method.
- The processStateChange() method checks that the XINS API has returned a
result and pass the result to the applyResult() method.
- The applyResult() method looks for an errorcode attribute in the result.
If there is one, an alert window is shown with the error code, otherwise the content
of the result is inserted in the HTML.
- The insertion is done at HTML tag <span id="answer"><span> by the Javascript
code document.getElementById("answer").innerHTML = answer;.
You can have a look at the source code of this HTML page to fully understand this example.
Next