【发布时间】:2017-07-17 12:16:54
【问题描述】:
如果我想创建使用 freegeoip.net 属性的表,如何使用 jquery 数据表?项目的目标是从 freegeoip.net 接收数据,然后将其放入数据表中。这是我的html代码。我也尝试将数据保存到 html 中
<!DOCTYPE html>
<html>
<head>
<title>idAddress</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<input id="ip" type="text" name="textField" placeholder="Enter Ip Address"><br/><br/>
<input id="button" type="submit" value="submit Adress">
<input id="button2" type="button" value="sent" onclick="cheak()">
<p id="p"></p>
<script type="text/javascript">
var ipAdd;
window.cond = false;
var index = 0;
function validateIp(ipAdd) {
var save = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/;
return save.test(ipAdd);
}
function validate() {
index++; //for storing data in array . .
ipAdd = $("#ip").val();
if (validateIp(ipAdd)) {
console.log("valid");
} else {
console.log("invalid");
}
}
$("#button").bind("click", validate);
function cheak(){
var info = [];
$.ajax({
url:'https://freegeoip.net/json/'+ipAdd,
type:"Get",
dataType:'json',
success:function(data){
info[index] = JSON.stringify(data);
document.getElementById("p").innerHTML = info[index];
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("please cheak your IpAdress");
}
});
}
</script>
</body>
</html>
【问题讨论】:
-
Uncaught ReferenceError: validateEmail is not defined在运行您的 sn-p 时。那应该是一个开始 -
请查看答案部分的 sn-p。我已对您的代码进行了更改。根据您的要求,只需按给定顺序添加数据表 js 和 jquery。
标签: javascript jquery datatables