贴一段Jquery代码。大家看看为什么data无法获得
$(function(){
var jqxhr = $.getJSON('http://chaxun.1616.net/s.php?type=ip&output=json&callback=json&_='+Math.random(),
function (data) {
alert(data.ip);
})
.error(function () { alert("error"); })
});
这段代码是想在页面加载时获得IP地址的,结果返回error啦。所以请大家看看,如果谁发现问题所在。分全给你啦,页面代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="<%=path %>/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/getAddress.js"></script>
</head>
<body>
</body>
</html>
[解决办法]
http://chaxun.1616.net/s.php?type=ip&output=json&callback=json
这个URL返回的数据格式是这样的!
json({"Ip":"111.85.194.242","Isp":"贵州省贵阳市 联通","Browser":"","OS":"","QueryResult":1}){"Ip":"111.85.194.242","Isp":"贵州省贵阳市 联通","Browser":"","OS":"","QueryResult":1}