javascript - 使用 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 包含哪些参考库?
或者我缺少任何语法?
解决方案
推荐阅读
- python - 我需要一个包含所有可打印字符的列表
- php - 为什么 PHP 会忽略任何字符串开头的换行符
- python-3.x - Altair 离线渲染
- perl - 用于 Web 自动化的 Perl 模块
- android - 在 Android Studio 中测试 Firestore 登录
- python - 尝试使用 Django 构建用户注册表单时出现属性错误
- android - 如何在不验证(登录/注册)用户的情况下保护 Firebase 实时数据库?
- django - Django-rest-framework 性能问题
- python - 查找数据框所有列的唯一值
- ssl - curl --cacert 错误“curl:(60)SSL:没有替代证书主题名称与目标主机名匹配”