Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created February 28, 2012 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiroshi/1932366 to your computer and use it in GitHub Desktop.
Save s-hiroshi/1932366 to your computer and use it in GitHub Desktop.
jQuery > simple Ajax sample
<?php
$value = htmlspecialchars($_GET["test"]);
header("Content-Type: text/html; charset=UTF-8");
echo $value;
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Ajax sample used jQuery</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
</head>
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
</head>
<body>
<!--
- GETメソッドで送信したクエリ文字(This is test)を送信し結果を表示(#respons)する。
-->
<div id="response"></div>
<script>
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
$('#response').text(xhr.responseText);
}
}
}
xhr.open('GET', './ajax_server.php?test=This is test.');
xhr.setRequestHeader('If-Modified-Since', 'Thu, 01 Jun 1970 00:00:00 GMT');
xhr.send(null);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment