comparison 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
comparison
equal deleted inserted replaced
149:88d1f5caebd7 150:4a882ba147e4
1
2 function submitAjax()
3 {
4 var xhr;
5 try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
6 catch (e)
7 {
8 try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
9 catch (e2)
10 {
11 try { xhr = new XMLHttpRequest(); }
12 catch (e3) { xhr = false; }
13 }
14 }
15
16 xhr.onreadystatechange = function()
17 {
18 if(xhr.readyState == 4)
19 {
20 if(xhr.status == 200)
21 {
22 var o = document.getElementById( "output" );
23 o.innerHTML = xhr.responseText;
24 }
25 else
26 {
27 var o = document.getElementById( "output" );
28 o.innerHTML = "Failed HTTP code " + xhr.status + " " + xhr.responseText;
29 }
30 }
31 };
32
33 data = 'ajax=1';
34 data = data + '&id=' + escape(document.forms[0].id.value );
35 data = data + '&captcha=' + escape( document.forms[0].captcha.value );
36 data = data + '&id=' + escape(document.forms[0].id.value );
37 data = data + '&captcha=' + escape( document.forms[0].captcha.value );
38 data = data + '&name=' + escape( document.forms[0].name.value );
39 data = data + '&mail=' + escape( document.forms[0].mail.value );
40 data = data + '&body=' + escape( document.forms[0].body.value );
41 xhr.open("POST", "/cgi-bin/comments.cgi", true);
42 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
43 xhr.send(data);
44 }