140 likes | 153 Views
Still working on them, should be done in the next couple of days. Final project presentations will be on Dec. 2nd. Questions? Learn about AJAX, web servers, AJAX syntax, GET vs POST, AJAX status codes, and more.
E N D
Lab 13: AJAX User Interface Lab: GUI Lab Nov 18th, 2014
Project 4 Grades • Still working on them, should be done in the next couple days.
Final Project • All presentations will be on Dec 2nd • I will post presentation details today • Questions?
Web Servers • Serve content to webpages • Generally where the interesting content comes from
AJAX • Asynchronous JavaScript and XML • The protocol webpages use to talk to servers • Not actually a new language just a way of programming
AJAX Syntax varreq = new XMLHttpRequest(); //for IE5 and 6 varreq = new ActiveXObject(“Microsoft.XMLHTTP");
AJAX Syntax req.open(“GET”, “someURL”, true); req.send(); req.open(“POST”, “someURL”, true); req.send();
GET vs POST • GET • Generally intended for pulling small information • Cannot send very much information • Faster • POST • Generally meant for updating server data • Unlimited information limit • Slower
AJAX Syntax req.onreadystatechange = function() { if(req.readyState == 4 && req.httpStatus == 200) { //successful } }
AJAX Status Codes • req.readyState • 0: request not initialized • 1: server connection established • 2: request received • 3: processing request • 4: request finished and response is ready • req.status • 200: “OK” • 404: “Page not found”
AJAX async • true • request runs and will call onreadystatechange when its status changes • default status • false • will halt javascript execution until the request is finished • rarely used and normally only for short things
Reading AJAX result • req.responseText - the response as straight text in a string • req.responseXML – a structured object with properties but only works if the response was formatted in XML
Sending Variables in AJAX url.asp?attr1=var1&attr2=var2
More on AJAX • see here: http://www.w3schools.com/ajax/default.asp