CH12 Ajax
CH12 Ajax
Spring 2025
AJAX
Yonsei University
https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX
https://www.w3schools.com/xml/ajax_intro.asp
2
AJAX CAS2109-01
3
AJAX CAS2109-01
Source: Internet & World Wide Web How to Program, 5/e, Pearson
4
AJAX CAS2109-01
5
AJAX CAS2109-01
Source: Internet & World Wide Web How to Program, 5/e, Pearson 6
AJAX CAS2109-01
7
AJAX CAS2109-01
동영상
8
AJAX CAS2109-01
https://jsonplaceholder.typicode.com/
9
AJAX CAS2109-01
10
AJAX CAS2109-01
Method Description
new XMLHttpRequest() Creates a new XMLHttpRequest object
open(method,url,async,user,psw) Specifies the request
method: the request type GET or POST
url: the file location
async: true (asynchronous) or false (synchronous)
user: optional user name
psw: optional password
send() Sends the request to the server
Used for GET requests
send(string) Sends the request to the server.
Used for POST requests
setRequestHeader() Adds a label/value pair to the header to be sent
getAllResponseHeaders() Returns header information
getResponseHeader() Returns specific header information
abort() Cancels the current request
https://www.w3schools.com/xml/ajax_xmlhttprequest_create.asp 11
AJAX CAS2109-01
Property Description
onreadystatechange Defines a function to be called when the readyState
property changes
The onreadystatechange event is triggered four times (1-
4), one time for each change in the readyState
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
responseText Returns the response data as a string
responseXML Returns the response data as XML data
status Returns the status-number of a request
200: "OK"
403: "Forbidden"
404: "Not Found"
For a complete list go to the Http Messages Reference
statusText Returns the status-text (e.g. "OK" or "Not Found")
12
https://www.w3schools.com/xml/ajax_xmlhttprequest_response.asp
AJAX CAS2109-01
13
AJAX CAS2109-01
https://www.w3schools.com/xml/cd_catalog.xml 15
AJAX CAS2109-01
https://www.w3schools.com/jquery/jquery_ajax_load.asp
16
AJAX CAS2109-01
• The $.get() method requests data from a server with GET request:
$.get(URL, callback);
$("button").click(function(){
$.get("demo_test.asp", function(data, status){
alert("Data: " + data + "\nStatus: " + status);});
});
• The $.post() method requests data from the server using POST:
$.post(URL, data, callback);
$("button").click(function(){
$.post("demo_test_post.asp", {name: "Donald Duck", city: "Duckburg"},
function(data, status){alert("Data: " + data + "\nStatus: " + status);});
});
https://www.w3schools.com/jquery/jquery_ajax_get_post.asp
17
JavaScript CSI-2109-01
18