AJAX Flashcards

1
Q

AJAX stands for _______ _________ and _______. AJAX makes our applications feel more _________ as data is being communicated between the server and client with ____ _______ ________.

A

AJAX stands for Asynchronous JavaScript and XML. AJAX makes our applications feel more responsive as data is being communicated between the server and client with no page refresh.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

AJAX requires:
1)
2)
3)

A

AJAX requires:

1) An HTML page
2) Javascript to send and receive server data
3) a PHP script to process data on the server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Use XMLHttpRequest (XHR) objects to _________.

A

Use XMLHttpRequest (XHR) objects to interact with servers. The XMLHttpRequest API is the core of Ajax. You can retrieve data from a URL without having to do a full page refresh. This enables a Web page to update just part of a page without disrupting what the user is doing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

XMLHttpRequest: The core of AJAX (syntax)

A

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e){
console.log(xhr.readyState);
if(xhr.readyState === 4){
console.log(xhr.responseText);// modify or populate html elements based on response.
}
};

xhr. open(“GET”, “path-to-php.php”, true); //true means it is asynchronous // Send variables through the url
xhr. send();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Using POST (syntax)

A

xhr. open(“POST”,”path-to-php.php”,true);
xhr. setRequestHeader(“Content-type”,”application/x-www-form-urlencoded”);
xhr. send(“fname=Henry&lname=Ford”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

responseText treats the returned data as _____ _____ whereas responseXML treats it like an ______ _______.

A

responseText treats the returned data as raw text whereas responseXML treats it like an XML Document.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

responseText (syntax)

A

xmlDoc = xhr.responseXML;

x=xmlDoc.getElementsByTagName(“tag-name”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Developers may use DOM ______ methods on the XML document object to traverse and retrieve values contained in the XML structure.

Name three:

A

Developers may use DOM traversal methods on the XML document object to traverse and retrieve values contained in the XML structure.

.childNodes property (nodeList)
.nodeValue property
.getAttribute method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Using JSON to quickly 0utput a JSON object from PHP, use the following code:

A
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If the data returned by the server is in JSON format, Javascript can easily turn this into a native Javascript object using Javascript’s built in function JSON.parse()

A
var response = JSON.parse(httpRequest.responseText); 
//the variable response is now an object representation of the responseText JSON-formatted string
How well did you know this?
1
Not at all
2
3
4
5
Perfectly