Skip to content

Instantly share code, notes, and snippets.

@taitokiss
Last active November 11, 2018 02:47
Show Gist options
  • Save taitokiss/9116b61a914b27733c777dd2db04514b to your computer and use it in GitHub Desktop.
Save taitokiss/9116b61a914b27733c777dd2db04514b to your computer and use it in GitHub Desktop.
ajax 1つデータを送り、結果を表示
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ajax Test1</title>
</head>
<body>
<button id="button">送信</button>
<div><br></div>
<div id="result">戻り値をここに表示します</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$(function(){
$("#button").click(function(event){
$.ajax({
type: "GET",
url: "ajax_test1.php",
data: { val: 99 },
dataType : "text"
}).done(function(data){
$("#result").text(data);
}).fail(function(XMLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
});
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment