JS版本的代码示例请下载quickstart代码

<!Doctype html>
<html lang="zh_cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>测试网页</title>
    <script src="../js/jquery.min.js"></script>
    <script>
        function login_error(XMLHttpRequest, textStatus, errorThrown) {
            console.log("status:" + XMLHttpRequest.status);
            console.log("readyState:" + XMLHttpRequest.readyState);
            console.log("textStatus:" + textStatus);
        }
        function getSubjectList() {
            var data = {
                "appID": "fcd2fe1f-b44b-4a7c-af1d-35fd9de16017",
                "secretKey": "123456"
            };
            var login_settings = {
                "async": true,
                "crossDomain": true,
                "url": "http://112.124.45.134:9000/xbg/api/appLogin",
                "method": "POST",
                "data": JSON.stringify(data),
                "success": login_success,
                "error": login_error
            };
            $.ajax(login_settings);
        }
        function login_success(response) {
            console.log(response);

            //todo 错误处理

            var token = response.token;

            var api_settings = {
                "async": true,
                "crossDomain": true,
                "url": "http://112.124.45.134:9000/quickstart/subject/categoryList",
                "method": "GET",
                "success": api_success,
                "error": login_error,
                "beforeSend": function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("api_gateway_auth_token", token);
                },
            };
            $.ajax(api_settings);
        }
        function api_success(response) {
            $("#resp").text(JSON.stringify(response));

        }
    </script>

</head>
<body>
<div style="text-align:center; margin-top: 20px;">
    <input id="btn" type="button" style="font-size: 500px;" onclick="getSubjectList()" value="获取服务器数据"> </input>
</div>
<div style="text-align: center;">返回数据:</div>
<div id="resp" style="text-align:center; margin-top: 20px;"></div>

</body>
</html>

results matching ""

    No results matching ""