Javascript getjson查询不工作
Json页面是: 我的代码是Javascript getjson查询不工作,javascript,jquery,json,Javascript,Jquery,Json,Json页面是: 我的代码是 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $.getJSON("http
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.getJSON("http://localhost/02/t.php",function(result){
alert(result.ip);
});
});
});
</script>
$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$.getJSON(“http://localhost/02/t.php,函数(结果){
警报(result.ip);
});
});
});
此简单代码不起作用:(看起来像支持jsonp
,您可以执行以下操作:
$('button').click(function () {
$.ajax({
url: "http://freegeoip.net/json/59.92.78.49",
dataType: "jsonp",
success: function (result) {
alert(result.ip); // server response
}
});
});
如何“不起作用”?您在控制台中看到了什么?有错误吗?此页面是否也在
http://localhost
?t.php是否回显有效的JSON文件?您可以为JSONP提供对该服务的回调。将?callback=JSONP
添加到URL的末尾。@Andy:在jQuery中,您希望执行?callback=?
。它将替换?
给你。是的,我刚注意到。