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
What event do you use to determine when a user has clicked on an input box?
onfocus
What event do you use to determine when a user has clicked out of an input box?
onblur
What event do you use to test if a user has rolled over an image or div in a page?
onmouseover
What event do you use to test if a user has moved the mouse from outside the dimensions of an image or div?
onmouseout
What event is raised when a form is submitted?
onsubmit
What event is raised when a window is resized?
onresize
What event is raised if an image cannot be loaded?
onerror
You can assign an event handler easily by using the ‘=’ sign, but what if you want to add more than one?
Use the function addEventListener myBtn.addEventListener(p1, p2, p3) p1 = event name (without 'on' in front) p2 = the event handler p3 = Use capture
What level DOM is it when you are adding event handlers directly to controls?
DOM Level 0
What level of DOM is it when you are adding event handlers via an interface?
DOM Level 2
What order are event handlers called when added using addEventListener?
It isn’t guarenteed
If an object called Tab has a property called onclick, and a function called showTab is assigned to it. To what does “this” refer to in the showTab function?
To the Tab object.
In what situation should you avoid using “this” in javascript and why?
When writing event handlers (because I.E. deals with this differently when using attachEvent, DOM level 2).
What should you use instead of using ‘this’ in an event handler?
Use the object passed to the handler
What is an “activated object”?
An object on a page that has been triggered by an event (basically it’s the event object passed to a event handler in DOM level 2)
What is one issue with request objects that must be taken into account when multiple requests are in play?
You must be careful that subsequent calls don’t trounce the first request object.