Mercurial > boosterpack
annotate perltest/index.html @ 9:9652dc713ba6 boosterpack
working on adding to rlmcintyre.com
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 26 Jun 2010 20:06:08 -0400 |
parents | 477258d09353 |
children |
rev | line source |
---|---|
robert@0 | 1 <html> |
robert@0 | 2 <head> |
robert@0 | 3 <title>Simple Ajax Example</title> |
robert@0 | 4 <script language="Javascript"> |
robert@0 | 5 function xmlhttpPost(strURL) { |
robert@0 | 6 var xmlHttpReq = false; |
robert@0 | 7 var self = this; |
robert@0 | 8 // Mozilla/Safari |
robert@0 | 9 if (window.XMLHttpRequest) { |
robert@0 | 10 self.xmlHttpReq = new XMLHttpRequest(); |
robert@0 | 11 } |
robert@0 | 12 // IE |
robert@0 | 13 else if (window.ActiveXObject) { |
robert@0 | 14 self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); |
robert@0 | 15 } |
robert@0 | 16 self.xmlHttpReq.open('POST', strURL, true); |
robert@0 | 17 self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); |
robert@0 | 18 self.xmlHttpReq.onreadystatechange = function() { |
robert@0 | 19 if (self.xmlHttpReq.readyState == 4) { |
robert@0 | 20 updatepage(self.xmlHttpReq.responseText); |
robert@0 | 21 } |
robert@0 | 22 } |
robert@0 | 23 self.xmlHttpReq.send(getquerystring()); |
robert@0 | 24 } |
robert@0 | 25 |
robert@0 | 26 function getquerystring() { |
robert@0 | 27 var form = document.forms['f1']; |
robert@0 | 28 var word = form.word.value; |
robert@0 | 29 qstr = 'w=' + escape(word); // NOTE: no '?' before querystring |
robert@0 | 30 return qstr; |
robert@0 | 31 } |
robert@0 | 32 |
robert@0 | 33 function updatepage(str){ |
robert@0 | 34 document.getElementById("result").innerHTML = str; |
robert@0 | 35 } |
robert@0 | 36 </script> |
robert@0 | 37 </head> |
robert@0 | 38 <body> |
robert@0 | 39 <form name="f1"> |
robert@0 | 40 <p>word: <input name="word" type="text"> |
robert@0 | 41 <input value="Go" type="button" onclick='JavaScript:xmlhttpPost("./simple-ajax-example.cgi")'></p> |
robert@0 | 42 <div id="result"></div> |
robert@0 | 43 </form> |
robert@0 | 44 </body> |
robert@0 | 45 </html> |