<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  void Page_Load()
  {
    if (Request.QueryString["sendData"] != null &&
        Request.QueryString["sendData"] == "ok")
    {
      Response.Write("Powitanie z serwera");
      Response.End();
    }
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>AJAX with ASP.NET</title>

  <script language="Javascript" type="text/javascript">
function getXMLHTTP() {
  var XMLHTTP = null;
  if (window.ActiveXObject) {
    try {
      XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
      }
    }
  } else if (window.XMLHttpRequest) {
    try {
      XMLHTTP = new XMLHttpRequest();
    } catch (e) {
    }
  }
  return XMLHTTP;
}

var XMLHTTP = getXMLHTTP();
if (XMLHTTP != null) {
  XMLHTTP.open("GET", "ajax.aspx?sendData=ok");
  XMLHTTP.onreadystatechange = stateChanged;
  XMLHTTP.send(null);
}

function stateChanged() {
  if (XMLHTTP.readyState == 4 && 
      XMLHTTP.status == 200) {
    alert(XMLHTTP.responseText);
  }
}
  </script>

</head>
<body>
  <p>Patrz i czekaj ...</p>
</body>
</html>
