透過 jQuery $ajax 串接 json 資料,並加入 HTML 中
===================================================================
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
method:"GET",
url:"https://randomuser.me/api",
}).done(function(msg){
console.log('全部的:',msg);
var email = msg.results[0].email;
$('div').append(email);
});
});
</script>
</head>
<body>
<div></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
method:"GET",
url:"https://randomuser.me/api",
success: function(data){
var email = data.results[0].email;
$('div').append(email);
}
});
});
</script>
</head>
<body>
<div></div>
</body>
</html>
====================================================================
[jQuery]jQuery取得JSON資料
https://blog.xuite.net/ahdaa/blog1/30797195-%5BjQuery%5DjQuery%E5%8F%96%E5%BE%97JSON%E8%B3%87%E6%96%99
jQuery向webApi提交post json資料
https://codertw.com/%E5%89%8D%E7%AB%AF%E9%96%8B%E7%99%BC/248455/
沒有留言:
張貼留言