【发布时间】:2017-07-04 07:40:37
【问题描述】:
我想在输入字段中输入一些内容,然后从 API 中获取值是否存在的响应。
如果邮政编码 (12345) 存在,API 将以真/假值响应。 http://192.168.100.100:8887/public?zipcode=12345
到目前为止,这是我的代码:
$(function() {
$('.positiveMessage, .negativeMessage').hide()
$('#submitBtn').on('click', function() {
var $zipcode = document.getElementById('searchZipCode').value
$.getJSON({
type: 'GET',
url: 'http://192.168.100.100:8887/public?zipcode=' + $zipCode,
success: result => {
//Goes through the array
$.each(result, function(i, info) {
$('body').append(info + '')
})
}
})
})
})
如您所见,我想通过在链接中添加一个变量来操作 API。
【问题讨论】:
-
你给了一个本地 ip ;)
-
操作!我会写出 JSON!
-
你正在循环一个布尔值?
-
是的。只有真或假