All pastes #68170 Raw Edit

v3x

public text v1 · immutable
#68170 ·published 2006-06-21 03:59 UTC
rendered paste body
<html>

<head>
  <title></title>

<script>
function createRequestObject() {

   var req;

   if(window.XMLHttpRequest){
      // Firefox, Safari, Opera...
      req = new XMLHttpRequest();
   } else if(window.ActiveXObject) {
      // Internet Explorer 5+
      req = new ActiveXObject("Microsoft.XMLHTTP");
   } else {
      // There is an error creating the object,
      // just as an old browser is being used.
      alert('Problem creating the XMLHttpRequest object');
   }

   return req;

}

// Make the XMLHttpRequest object
var http = createRequestObject();

function sendRequest(act) {

   // Open PHP script for requests
   http.open('get', 'getquote.php?act='+act);
   http.onreadystatechange = handleResponse;
   http.send(null);

}

function handleResponse() {

   if(http.readyState == 4 && http.status == 200){

      // Text returned FROM the PHP script
      var response = http.responseText;

      if(response) {
         // UPDATE ajaxTest content
         var textbox = document.getElementById("ajaxTest").innerHTML;
         document.getElementById("ajaxTest").innerHTML = textbox + ' ' + response;
      }

   }

}
</script>
</head>

<body>
<a href="#" onclick="sendRequest()">Click to test</a><br \>
<form method="post" action="?act=1">
<textarea id="ajaxTest" rows=10 cols=50 wrap="on" name="text"></textarea><br \>
<input type="submit" name="submit" value="Go">
</form>
<?php
	if($_GET["act"])
		echo $_POST["text"];
?>

</body>

</html>