createXML() function is used to create a XML document, just stringing together the text. value pairs turn into XML elements, where the element <name> is the name of the pair, and the content of the element is the value, like <coinid>123</coinid>.

Much of the below statements are self-explanatory. SingleIUD() function executes
1)Collects the form input value.
2)Creats an xml document.
3)Create an XMLHttpRequest object.
4)Create the function to be executed when the server response is ready.
5)Send the request to the php file on the server.
6)Receive xml document response from the php file on the server and.
7)Finally parse the xml document.

When the AJAX is sent request to the PHP file,
1)PHP receive xml document request.
2)Parse xml document using DOM object.
3)Create a response xml docment.
4)Send response xml document back to the AJAX XMLHttpRequest object.

The request is processed by the ajcoindml.php. Here i used PHP XML DOM, compare to SAX, DOM has an in-memory tree structure, provide to modify an XML document. The DOM XML parser functions are part of the PHP core, no installation needed to use these functions.

find_node_value_xml() function contains
1)Initialize and creates a DOM Document object.
2)Load the xml.
3)Loop through all elements of the element:
4)Find the node value of the element and return it.

The ajcoindml.php returns an XML document containing the results. Following a successful request, the object returns of the XML document that was retrieved from the ajcoindml.php using the xmlCoin.responseXML;

<response>
<coinid></coinid>
<error></error>
</response>

The statment (xml.getElementsByTagName("coinid")[0]).childNodes[0].nodeValue; is used to parse XML response.

2 comments:

Compare to jquery, this is more simple and easy to write. For jquery you have to install jquery javascript, and understand about the functions and flow. This is also another way of AJAX and PHP communication