Create interface - client loads web page - client.html (=index.html) - this script without fn updateText()
In fn updateText() are steps 2,3,4 :
Making a request to Server v_req_obj.send() ;
Receiving response from server var response = v_req_obj.responseText ;
Updating Web Page document.getElementById('server_response').value = response ;
Differences POST method vs GET method
In client.html (=index.html) URL QRY params are send parameters : v_req_obj.send(user_text="+current_text)
v_req_obj.open GET -> POST and no URL_QRY_PARAMS "?...&..."
New line v_req_obj.setRequestHeader before line v_req_obj.send
In server.php $_REQUEST ($_POST) instead $_GET
F12 -> Network shows no more URL_QRY_PARAMS
UML diagram of XMLHttpRequest (properties and methods)
We use object XMLHttpRequest to interact with server.
REQUEST PROPERTIES :
readyState : it is used to determine the current status of the request
0: request not initialized by client yet
1: connection is established with the server
2: request is received by the server
3: server is processing request
4: response is ready and received at client end
status : it specifies if request was successful or not
200: OK i.e. request was successful
404: page was not found
Onreadystatechange : it holds a function which runs (triggers) when (on event) value of readyState changes
RESPONSE PROPERTIES :
v_req_obj.responseText
v_req_obj.responseXML
REQUEST METHODS :
open( method , server url , asynchronous )
send() for GET Method or send(data) for POST method