Ajax Flashcards

1
Q

What does AJAX stand for?

A

Asynchronous JavaScript and XML

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

Why Web Apps?

A

Everyone has a browser

Automatic updates when accessed in browser

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

Downside of Web Apps

A

GUI is poor. HTML is OK for static documents but rubbish for programs
HTTP is a poor protocol for communication

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

Why AJAX?

A

Instant updates
Asynchronous results
More widgets than GUI elements

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

What is the basic ajax process?

A

JAVASCRIPT:

  1. Define a Request Object
  2. Initiate Request (with GET/ POST)
  3. Handle Response

HTML

  1. Load JavaScript
  2. Designate control that initiates request
  3. Give IDs to input elements, and to output region.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Ajax Process:
JavaScript:
Code for 1. Define a Request Object

A
function getRequestObject(){
if(window.XMLHttpRequest){
return (new XMLHttpRequest());
}else
}return(null);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Ajax Process:
JavaScript
Code for 2. Initiating a request

A
function initiateRequest(resultsRegion){
var req = getRequestObject();
req.onreadystatechange =
function() {handleResponse(req, resultsRegion)};
req.open("GET", "myFile.html", true);
req.send(null);
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Ajax Process:
JavaScript:
Code for 3. Handle Response

A
function handleResponse(req, resultsRegion){
if(req.readyState == 4) && (req.Status == 200){
htmlInsert(resultsRegion, req.responseText);
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or false; JavaScript lets you pass functions around?

A

True

As in Ajax Process, JS, (2) Initiating a Request: reques.onreadystatechange = handleResponse;

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

Describe JavaScript first class functions

A

JS lets you pass around functions, ie access them in another function:

request.onreadystatechange = handleResponse;

The code from the Initiate Request (2) function has a onreadystatechange that equals another function; the handleResponse (3) function.

JavaScript allows anonymous functions

var request = getRequestObject();

request.onreadystatechange = function() {handleResponse(request)}

By calling and putting the handleResponse function within a function(){handleReponse(request)}; you make the function anonymous rather than just goin request.ORSC = handleResponse;

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

Technologies needed in place to use Ajax?

A
Sever-side language such as JSP, .NET or PHP.
JavaScript
Web Browser
Servlets
Server, tomcat?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the correct way to use anonymous functions?

A

Use an anonymous function with a local copy of the request object embedded in the code ie for the 2. Initiate Request part of of the Ajax process:

function sendRequest(){
    request = getRequestObject();
    request.onreadystatechange = function() {handleResponse(request); };
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the design deficiencies with using HTML to acheive Ajax (entProg/wk3)

A

Content is same on each request (HTML page doesnt change dynamically)

A better way to do this is with a JSP page.

HMTL page url is hardcoded into ajax-utils.js - instead make a generic function (address) then pass the page in from the HTML, so it can be used again with out areas.

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

Design deficiencies with using JSP pages to achieve Ajax (entProg/wk3)

A

The URL stays the same even when the output changes

If the browser caches the page, it returns wrong time for example - SolutionL cache-control and pragma headers

JSP is wrong tech if using Java - JSP is best for lots of HTML and little but no logic/java - Solution: use Servlet.

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

Design deficiencies with Servlet way of achieving Ajax (entProg/wk3)

A

Alerts are usually reserved for warnings, users prefer results in a page
Solution: use dynamic HTML to update page

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

Name 3 styles of Ajax

A

Content-centric Ajax: Server sends exact HTML to be displayed. Client simply inserts content into these tables. Not good if the server is going to be used for different things. May only want to send data:

Data-centric Ajax:
The server sends raw data
The client parses the data and builds HTML

Script-centric Ajax:
Server sends JavaScript functions
Client executes functions
Inflexible - requires server to know too much about client

17
Q

What advantage does Ajax have over standard client server apps using HTML/HTTP

A

Communicate with server without leaving the page
Frequent small updates - faster
Data is kept on screen - no refresh
Ajax allows more like desktop apps

18
Q

Advantages and disadvantages of XML

A

Advantages - Human readable, structured metadata

Disadvantages - Verbose, larger to procress

19
Q

Advantages and disadvantages of JSON

A

Advantages - lightweight (serialisation), more efficient than XML, mapped straight to objects.

Disadvantages - not easily read by humans. No error handling. Security issues with data transfer

20
Q

Advantages and disadvantages of plain text

A

Advantage: extremely lightweight, simple to process
Disadvantage: only basic data, no standard way to represent binary data, problems to SQL

21
Q

Ajax Process:
JavaScript:
Code for 3. htmlInsert

A
function htmlInsert(id, htmlData){
document.getElementById(id).innerHTML = htmlData;
}
22
Q

HTML code for ajax

A

<div></div>