AJAX Response

ក្រោយ​ពី​ទទួល​បាន​សំណើរ​រួច​ហើយ server អាច​នឹង​ធ្វើ​ការឆ្លើយ​តប​មកវិញ ដោយ​បញ្ជូន​នូវ​ទិន្នន័យ​ដែល​យើង​ចង់​បាន ឬ​មិន​បញ្ជូន​ដោយ​ហេតុផល​ណាមួយ​។ ហើយ​នៅ​ពេល​ដែល server ធ្វើការ​ឆ្លើយតប​មកវិញ ហេតុការណ៍​ឈ្មោះ xhttp.onreadystatechange នឹង​កើត​មាន​ឡើង ដែល​យើង​អាច​ភ្ជាប់​វា​ទៅ​នឹង​ក្បួន​វិធី​ឆ្លើយតប​ហេតុការណ៍​ណា​មួយ​បាន​។ ពិនិត្យ​កម្មវិធី​ខាង​ក្រោម​នេះ៖
var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    alert(this.responseText);
  }
};

xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
The onreadystatechange Property
Property Description
onreadystatechange Defines a function to be called when the readyState property changes
readyState Holds the status of the XMLHttpRequest.
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
status 200: "OK"
403: "Forbidden"
404: "Page not found"
For a complete list go to the Http Messages Reference
statusText Returns the status-text (e.g. "OK" or "Not Found")