AJAX Flashcards
What does the function “escape()” do in javascript?
Similar to filter_var, it cleans up the url to remove any characters that should not be there. (note this is deprecated)
What should you use instead of escape()?
encodeURI or encodeURIComponent
What function do you use to reverse the result of encodeURI?
decodeURI
What function do we use to request a “request object”?
try { request = new XMLHttpRequest(); } catch (tryMS) { try { request = new ActiveXObject("Mxsml2.XMLHTTP"); } catch (otherMS) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = null; } } }
How do you configure a “request object” to retrieve information
var url = “getDetails.php?ImageID=” + encodeURI(itemName);
request. open(“GET”, url, true);
request. onreadystatechange = displayDetails;
request. send(null);
What do the parameters in request.open call do?
request.open(Method, url, asynchronous);
Method - GET or POST
url - The url that will respond to the request
asynchronous - Is the request sync or async
When assigning a function to a callback parameter do you include parenthesis?
No - you don’t include the parenthesis unless you are making a function call. i.e.
myCallback = coolCallback;
What does the readyState property on the request object do?
Contains a value that represents the current state of the object
What does the status property on the request object do?
Contains a status code returned by the server indicating success or if a requested resource is missing (i believe it can contain far more than this however).
What does the property responseXML on the request object do?
Contains information sent back by the server in XML format (this is empty unless the server responds in XML)
What does the statusText property on the request object do?
Provides the status code message returned by the server, i.e. OK for status 202.
What does the responseText property on the request object do?
Contains textual information sent back by the server (this may be empty if the server sends the data back as XML).
What value will the readyState property have when the server completes processing?
4 (starts at 0)
What event do you use to make sure code is executed after the page is loaded
onload
What event do you use to trigger code when an image or div on a page is clicked?
onclick