【发布时间】:2018-04-19 18:26:26
【问题描述】:
我正在尝试使用 api 构建一个从 api 获取 JSON 数据的应用程序,我需要在我的索引页面上有一个按钮,然后当我输入汽车注册信息时,信息会加载到另一个页面中。
我目前通过用户输入、标签和提交按钮加载信息,但我不知道如何将输入和按钮放在单独的页面上,然后加载 json 数据。这是我到目前为止所拥有的。
<form id="vehicle-smart-sample-form">
<label for="reg">Enter your reg</label>
<input type="text" id="reg"/>
<a href="stats.html"><button type="submit">Search</button></a>
</form>
$(document).ready(function () {
$("#vehicle-smart-sample-form").submit(function (e) {
e.preventDefault();
var reg = $("#reg").val();
$.ajax({
"async": true,
"crossDomain": true,
"url": "https://www.getvehiclesmart.com/rest/vehicleData?reg=" + reg + "&isRefreshing=false&appid="+myAppId,
"method": "GET",
"headers": {
"Content-Type": "application/text",
"Accept": "application/json",
"Cache-Control": "no-cache"
}
})
});
【问题讨论】:
标签: javascript jquery json api