Mercurial > hg > chronicle
annotate themes/blog.steve.org.uk/ajax.js @ 150:4a882ba147e4
Updated to allow Ajax to be used for comment submission.
author | Steve Kemp <steve@steve.org.uk> |
---|---|
date | Mon, 31 Dec 2007 00:01:51 +0000 |
parents | |
children | 8b0c547cd015 |
rev | line source |
---|---|
150
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
1 |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
2 function submitAjax() |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
3 { |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
4 var xhr; |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
5 try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
6 catch (e) |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
7 { |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
8 try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
9 catch (e2) |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
10 { |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
11 try { xhr = new XMLHttpRequest(); } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
12 catch (e3) { xhr = false; } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
13 } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
14 } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
15 |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
16 xhr.onreadystatechange = function() |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
17 { |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
18 if(xhr.readyState == 4) |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
19 { |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
20 if(xhr.status == 200) |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
21 { |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
22 var o = document.getElementById( "output" ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
23 o.innerHTML = xhr.responseText; |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
24 } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
25 else |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
26 { |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
27 var o = document.getElementById( "output" ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
28 o.innerHTML = "Failed HTTP code " + xhr.status + " " + xhr.responseText; |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
29 } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
30 } |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
31 }; |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
32 |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
33 data = 'ajax=1'; |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
34 data = data + '&id=' + escape(document.forms[0].id.value ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
35 data = data + '&captcha=' + escape( document.forms[0].captcha.value ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
36 data = data + '&id=' + escape(document.forms[0].id.value ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
37 data = data + '&captcha=' + escape( document.forms[0].captcha.value ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
38 data = data + '&name=' + escape( document.forms[0].name.value ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
39 data = data + '&mail=' + escape( document.forms[0].mail.value ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
40 data = data + '&body=' + escape( document.forms[0].body.value ); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
41 xhr.open("POST", "/cgi-bin/comments.cgi", true); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
42 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
43 xhr.send(data); |
4a882ba147e4
Updated to allow Ajax to be used for comment submission.
Steve Kemp <steve@steve.org.uk>
parents:
diff
changeset
|
44 } |