Mercurial > hg > chronicle
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/themes/blog.steve.org.uk/ajax.js Mon Dec 31 00:01:51 2007 +0000 @@ -0,0 +1,44 @@ + +function submitAjax() +{ + var xhr; + try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); } + catch (e) + { + try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } + catch (e2) + { + try { xhr = new XMLHttpRequest(); } + catch (e3) { xhr = false; } + } + } + + xhr.onreadystatechange = function() + { + if(xhr.readyState == 4) + { + if(xhr.status == 200) + { + var o = document.getElementById( "output" ); + o.innerHTML = xhr.responseText; + } + else + { + var o = document.getElementById( "output" ); + o.innerHTML = "Failed HTTP code " + xhr.status + " " + xhr.responseText; + } + } + }; + + data = 'ajax=1'; + data = data + '&id=' + escape(document.forms[0].id.value ); + data = data + '&captcha=' + escape( document.forms[0].captcha.value ); + data = data + '&id=' + escape(document.forms[0].id.value ); + data = data + '&captcha=' + escape( document.forms[0].captcha.value ); + data = data + '&name=' + escape( document.forms[0].name.value ); + data = data + '&mail=' + escape( document.forms[0].mail.value ); + data = data + '&body=' + escape( document.forms[0].body.value ); + xhr.open("POST", "/cgi-bin/comments.cgi", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send(data); +}