tipdw/ajax.js

64 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-10-03 16:47:40 +08:00
layui.use(['form'], function () {
var form = layui.form;
form.on('submit(submit)', function (data) {
var index = layer.load(2, {tiem: 999999});
$.ajax({
type: "get",
2021-10-03 19:20:25 +08:00
url: "/api/",
2021-10-03 16:47:40 +08:00
data: data.field,
dataType: "json",
success: function (data) {
2021-10-03 19:20:25 +08:00
if (data.status === 0) {
2021-10-03 16:47:40 +08:00
let ipInfo = "";
2021-10-03 19:20:25 +08:00
ipInfo += " <tr>\n" +
" <td>IP:<span style='margin-left: 3px'> " + data.result.ip + "</span></td>\n" +
" </tr>\n";
ipInfo += " <tr>\n" +
" <td>国:<span style='margin-left: 3px'> " + data.result.ad_info.nation + "</span></td>\n" +
" </tr>\n";
2021-10-03 16:47:40 +08:00
ipInfo += " <tr>\n" +
2021-10-03 19:20:25 +08:00
" <td>省:<span style='margin-left: 3px'> " + data.result.ad_info.province + "</span></td>\n" +
2021-10-03 16:47:40 +08:00
" </tr>\n";
ipInfo += " <tr>\n" +
2021-10-03 19:20:25 +08:00
" <td>市:<span style='margin-left: 3px'> " + data.result.ad_info.city + "</span></td>\n" +
2021-10-03 16:47:40 +08:00
" </tr>\n";
2021-10-03 19:20:25 +08:00
ipInfo += " <tr>\n" +
" <td>区:<span style='margin-left: 3px'> " + data.result.ad_info.district + "</span></td>\n" +
" </tr>\n";
2021-10-03 16:47:40 +08:00
ipInfo += " <tr>\n" +
2021-10-03 19:20:25 +08:00
" <td>经纬度:<span style='margin-left: 3px'> " + data.result.location.lat + "," + data.result.location.lng + "</span></td>\n" +
2021-10-03 16:47:40 +08:00
" </tr>\n";
let head = "";
let html = "<table class=\"layui-table\">\n" +
" <thead>\n" +
" </thead>\n" +
" <tbody>\n" + ipInfo +
" </tbody>\n" +
"</table>";
console.log(html);
layer.open({
title: 'IP地址查询',
content: head + html,
btn: '确定',
btnAlign: 'c'
});
layer.close(index);
} else {
2021-10-03 19:20:25 +08:00
layer.msg(data.message, {icon: 2});
2021-10-03 16:47:40 +08:00
layer.close(index);
}
},
error: function () {
layer.close(index);
layer.alert('查询失败!');
}
});
})
});