0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

jQueryでJsonをGETする

Last updated at Posted at 2025-01-20

AjaxでJsonをGETする

index.html
<!DOCTYPE html>
<html lang="ja">
	<head>
		<meta charset="utf-8" />
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
		<script>
		
/****************************/
// {"name":"John","age":13}
/****************************/

$.ajax({
    type: "GET",
    url: "http://localhost/jquery/http-get.json",
    dataType:"json",
})
  
//通信が成功した場合の処理
.done(function(data) {

var data_stringify = JSON.stringify(data);
var json = JSON.parse(data_stringify);

var name = json["name"];
var age = json["age"];

alert(name);
alert(age);

})
  
//通信がエラーになった場合の処理
.fail(function(err) { })
  
//通信状態に関係なく毎回実行される処理
.always(function() { })
		</script>
	</head>
	<body>
	</body>
</html>
http-get.json
{"name":"John","age":13}
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?