AJAX Flashcards

1
Q

What does the function “escape()” do in javascript?

A

Similar to filter_var, it cleans up the url to remove any characters that should not be there. (note this is deprecated)

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

What should you use instead of escape()?

A

encodeURI or encodeURIComponent

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

What function do you use to reverse the result of encodeURI?

A

decodeURI

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

What function do we use to request a “request object”?

A
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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you configure a “request object” to retrieve information

A

var url = “getDetails.php?ImageID=” + encodeURI(itemName);

request. open(“GET”, url, true);
request. onreadystatechange = displayDetails;
request. send(null);

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

What do the parameters in request.open call do?

A

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

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

When assigning a function to a callback parameter do you include parenthesis?

A

No - you don’t include the parenthesis unless you are making a function call. i.e.
myCallback = coolCallback;

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

What does the readyState property on the request object do?

A

Contains a value that represents the current state of the object

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

What does the status property on the request object do?

A

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).

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

What does the property responseXML on the request object do?

A

Contains information sent back by the server in XML format (this is empty unless the server responds in XML)

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

What does the statusText property on the request object do?

A

Provides the status code message returned by the server, i.e. OK for status 202.

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

What does the responseText property on the request object do?

A

Contains textual information sent back by the server (this may be empty if the server sends the data back as XML).

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

What value will the readyState property have when the server completes processing?

A

4 (starts at 0)

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

What event do you use to make sure code is executed after the page is loaded

A

onload

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

What event do you use to trigger code when an image or div on a page is clicked?

A

onclick

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

What event do you use to determine when a user has clicked on an input box?

A

onfocus

17
Q

What event do you use to determine when a user has clicked out of an input box?

A

onblur

18
Q

What event do you use to test if a user has rolled over an image or div in a page?

A

onmouseover

19
Q

What event do you use to test if a user has moved the mouse from outside the dimensions of an image or div?

A

onmouseout

20
Q

What event is raised when a form is submitted?

A

onsubmit

21
Q

What event is raised when a window is resized?

A

onresize

22
Q

What event is raised if an image cannot be loaded?

A

onerror

23
Q

You can assign an event handler easily by using the ‘=’ sign, but what if you want to add more than one?

A
Use the function addEventListener
myBtn.addEventListener(p1, p2, p3)
p1 = event name (without 'on' in front)
p2 = the event handler
p3 = Use capture
24
Q

What level DOM is it when you are adding event handlers directly to controls?

A

DOM Level 0

25
Q

What level of DOM is it when you are adding event handlers via an interface?

A

DOM Level 2

26
Q

What order are event handlers called when added using addEventListener?

A

It isn’t guarenteed

27
Q

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?

A

To the Tab object.

28
Q

In what situation should you avoid using “this” in javascript and why?

A

When writing event handlers (because I.E. deals with this differently when using attachEvent, DOM level 2).

29
Q

What should you use instead of using ‘this’ in an event handler?

A

Use the object passed to the handler

30
Q

What is an “activated object”?

A

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)

31
Q

What is one issue with request objects that must be taken into account when multiple requests are in play?

A

You must be careful that subsequent calls don’t trounce the first request object.