如何使用php将this post的数据存储在我的mysql数据库中。我能够查看数据,但我很困惑将数据存储在表visitor_location上,列名如下,ip,city,region,country,loc,org。直到现在我能够在这里获取数据我的代码:
<script>
$.get("https://ipinfo.io/json", function (response) {
$("#ip").html("IP: " + response.ip);
$("#address").html("Location: " + response.city + ", " + response.region);
$("#details").html(JSON.stringify(response, null, 4));
}, "jsonp");
</script>
<div id="ip"></div>
<div id="address"></div>
<hr/>Full response: <pre id="details"></pre>
我想现在使用这个数据并使用php
存储在mysql数据库中答案 0 :(得分:0)
您需要加载jQuery库。
$.get("https://ipinfo.io/json", function (response) {
$("#ip").html("IP: " + response.ip);
$("#address").html("Location: " + response.city + ", " + response.region);
$("#details").html(JSON.stringify(response, null, 4));
/*
$data=JSON.stringify(response, null, 4);
$.ajax({
url: "myAction.php",
type : "POST",
data: $data,
beforeSend: function( xhr ) {
// do anythang
},
success: function( result ){
// do anythang
//console.log(result);
},
error: function( xhr ){
// do anythang
//console.log(xhr);
}
});
*/
}, "jsonp");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<div id="ip"></div>
<div id="address"></div>
<hr/>Full response: <pre id="details"></pre>
&#13;
首先取消注释ajax代码,然后输入有效的网址,然后尝试