首页 > 解决方案 > 使用 javascript/jQuery 使用 Web API

问题描述

我正在尝试使用此处找到的实时 Web api

http://dummy.restapiexample.com/api/v1/employee/1

但是我的代码永远不会成功,总是会出错。

请问我错过了什么?

<title>ASP.NET Web API</title>
<script src="~/Scripts/jquery-3.3.1.js"></script>


<script type="text/javascript">
    function GetAllEmployees()
    {
        jQuery.support.cors = true;
        $.ajax({
            url: 'http://dummy.restapiexample.com/api/v1/employee/1',
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                WriteResponse(data);
            },
            error: function (data) {
                alert("Error");
            }
        });
    }
 </script>
 </head>

 <body id="body">

<div>
        <label for="itId">ID:</label>
        <input type="text" id="custId" size="5" />
        <input type="text" id="locId" size="5" />
    <input id="getPerson" type="button" value="Search" onclick="GetAllEmployees();return false;" />

        <input type="text" class="form-control" id="getPersonResult" />
        <p id="item" />
    </div>
</body>
</html>

我需要为 js 和 jquery 包含哪些参考库?

或者我缺少任何语法?

标签: javascriptc#jqueryasp.netmodel-view-controller

解决方案


推荐阅读