Professional Documents
Culture Documents
Week 6, part 2
AJAX Design Pattern
AJAX Design Patterns
• Let’s learn through some interesting examples!
• Example 1: Widgets
– Technique involved: DOM Scripting & Event Handling.
– Content may require iFrame or XMLHttpRequest to
display.
http://appsrv.cse.cuhk.edu.hk/~csc4140/cgi-bin/week06_part2/widget/picture.html
http://appsrv.cse.cuhk.edu.hk/~csc4140/cgi-bin/week06_part2/widget/page.html
<DIV>
[HTMLElement].offsetTop mousedown
mouseup
mousemove
[HTMLElement].offsetLeft mouseover
mouseout
mouseup mousedown
When the mouseup event is detected,
the DIV should be dropped.
mousemove
It is easy to do…remove the event
listeners! mouseover
mouseout
<DIV>
<html>
<script language=JavaScript src=HTTP.js></script>
<script language=JavaScript>
var http = new HTTP(); OO-programming…this also
http.get(“hello.txt”); implies the possibility of
alert(http.result); creating more than one
</script> connections easily.
</html>
this.syn_get = function(url) {
this.request.open(“GET”, url, false);
Why using another variable ......
“temp”, but no using “this” };
inside the event handler?
var temp = this;
this.asyn_get = function (url) {
......
Because “this” will become this.onreadystatechange = function () {
the “XMLHttpRequest” if(temp.request.status == 200)
object inside the event ......
handler, not the “HTTP” };
......
object.
}
http://appsrv.cse.cuhk.edu.hk/~csc4140/cgi-bin/week06_part2/widget/Menu4140.js
http://appsrv.cse.cuhk.edu.hk/~csc4140/cgi-bin/week06_part2/typing/HTTP.js
http://appsrv.cse.cuhk.edu.hk/~csc4140/cgi-bin/week06_part2/typing/
xxx
Periodic Read
keypress event
xxx
http://appsrv.cse.cuhk.edu.hk/~csc4140/cgi-bin/week06_part2/typing/code_viewer.php