Created
February 28, 2012 12:53
-
-
Save s-hiroshi/1932366 to your computer and use it in GitHub Desktop.
jQuery > simple Ajax sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$value = htmlspecialchars($_GET["test"]); | |
header("Content-Type: text/html; charset=UTF-8"); | |
echo $value; | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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