<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><html>
<head>
<title>My JSP 'WarningWeather.jsp' starting page</title>
</head>
<script type="text/javascript" src="../jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function(){
alert("is ok");
$.ajax({
url: "http://m.weather.com.cn/data/101010100.html",
cache: true,
type: "getJSON",
success: function(js){
//document.write(js.weatherinfo.city);
var str = "<B>" + js.weatherinfo.city + "<B/><br/>" ;
str +=js.weatherinfo.date_y + " " + js.weatherinfo.week + "<br/>";
str += "农历:" + js.weatherinfo.date + "<br/>";
str += "气温:" + js.weatherinfo.temp1 + "<br/>" ;
str += "风力:" + js.weatherinfo.wind1 + "<br/>" ;
str += "建议:" + js.weatherinfo.index_d + "<br/>" ;
$("div").html(str) ;
},
dataType : "json",
});
});
</script>
<body>
<div id="results">
is ok
</div>
</body>
</html>页面显示不出来 有代码写在后台,通过ajax调用显示天气预报
<head>
<title>My JSP 'WarningWeather.jsp' starting page</title>
</head>
<script type="text/javascript" src="../jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function(){
alert("is ok");
$.ajax({
url: "http://m.weather.com.cn/data/101010100.html",
cache: true,
type: "getJSON",
success: function(js){
//document.write(js.weatherinfo.city);
var str = "<B>" + js.weatherinfo.city + "<B/><br/>" ;
str +=js.weatherinfo.date_y + " " + js.weatherinfo.week + "<br/>";
str += "农历:" + js.weatherinfo.date + "<br/>";
str += "气温:" + js.weatherinfo.temp1 + "<br/>" ;
str += "风力:" + js.weatherinfo.wind1 + "<br/>" ;
str += "建议:" + js.weatherinfo.index_d + "<br/>" ;
$("div").html(str) ;
},
dataType : "json",
});
});
</script>
<body>
<div id="results">
is ok
</div>
</body>
</html>页面显示不出来 有代码写在后台,通过ajax调用显示天气预报
解决方案 »
- 应用里出现application的问题
- request.getParameter无法获取中文
- 一个SSH架构的错误,很奇怪!请大家帮忙。在线等
- hiberate3查询结果与数据库不同步
- 中文字符编码的新问题!!非常怪!高人指点!解决分全送!!
- 关于SQLSERVER中日期转换问题
- jboss可以同时支持发布多个WAR包吗?部署WAR包出现以下错误:(请教!
- 菜鸟Norwaywoods() 请进来拿分!!!!!!
- weblogic & jbuilder 集成开发ejb的问题
- HIbernate4.0.1.Final 级联Bean 查询不出数据问题
- 购物车不能将相同的产品数量往上加啊,贴代码求高手帮忙解决,急
- apache的rewrite该怎么写
另一种情况是目标站点返回 jsonp 脚本,那么可以用(但你想访问的并不是):
$.get("http://m.weather.com.cn/data/101010100.html",
function(json) {
alert(123);
}, "jsonp"
);
具体参见:
http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin