如果我想创建使用freegeoip.net属性的表,我该如何使用jquery数据表?项目的目标是从freegeoip.net接收数据,然后将其放入数据表中。这是我的代码与HTML。我试图数据保存到HTML太jquery初学者的数据表
<!DOCTYPE html>
<html>
<head>
\t <title>idAddress</title>
\t <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>
'未捕获的ReferenceError:运行你的代码段时validateEmail不defined'。这应该是一个开始 – Jamiec
请在答案部分查看代码片段。我已对代码进行了更改。为了您的要求,只需要按给定的顺序添加数据表js和jquery。 –