Ajax Essay Grader

0
0



This automatic essay grader is a simple example of an Ajax (XMLHttprequest) interaction.

view source

print?

01 function grade(essay) {
02
03
04
05     // Mozilla version
06
07
08
09     if (window.XMLHttpRequest) {
10
11
12
13         xhr = new XMLHttpRequest();
14
15
16
17     }
18
19
20
21     // IE version
22
23
24
25     else if (window.ActiveXObject) {
26
27
28
29         xhr = new ActiveXObject("Microsoft.XMLHTTP");
30
31
32
33     }
34
35
36
37     essay=encodeURIComponent(essay);
38
39
40
41     xhr.open("POST","grade.php");
42
43
44
45     xhr.setRequestHeader(
46
47
48
49         'Content-Type',
50
51
52
53         'application/x-www-form-urlencoded; charset=UTF-8');
54
55
56
57     xhr.send(essay);
58
59
60
61     xhr.onreadystatechange=function() {
62
63
64
65         if (xhr.readyState==4) {
66
67
68
69             grade = xhr.responseText;
70
71
72
73             alert ("Nice essay. Your grade is " + grade);
74
75
76
77         }
78
79
80
81     }
82
83
84
85     return false;
86
87
88
89 }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>