html中怎么调用api接口,类似这样。
发布网友
发布时间:2022-04-20 03:42
我来回答
共1个回答
热心网友
时间:2023-09-02 10:27
引用jquery,有很方便的GET调用方法:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- src值为文件位置路径 -->
<script type="text/javascript" charset="UTF-8" src="javascript/jquery-1.12.1.js"></script>
<title>测试案例</title>
<!-- 语法:jQuery.getJSON(url,data,success(data,status,xhr)) -->
<script type="text/javascript" charset="UTF-8">
function getToken(){
$.getJSON("http://localhost/kdapi/api/access_token", {"id":111,"secret":2352532}, function(result){
alert(result.access_token);
});
}
</script>
</head>
<body>
<button onclick="getToken()" style="width: 120px; height: 60px;">获取Token</button>
</body>
</html>