设为首页 加入收藏

TOP

jQuery中的getJSON方法请求的接口有错误时的处理方法
2014-11-24 14:28:22 来源: 作者: 【 】 浏览:0
Tags:jQuery getJSON 方法 请求 接口 错误 时的 处理

在用jQuery中的getJSON方法时,通常会碰到请求的接口有错误的情况发生,这时我们可以用下面的方法来做处理,代码如下:


<script type="text/java script">


function GetDatas(url) {
try {
$.ajaxSetup({
error: function (x, e) {
$("#content").html("暂无具体内容!");
return false;
}
});

$.getJSON(url, function (data) {
if (data != null) {
$(".TitleStyle").html(data["root"][0]["data"][0]["Title"]);
var date = data["root"][0]["data"][0]["Date"];
if (date.length == 8) {
$("#strDate").html(date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8));
}
$("#strAuthor").html(data["root"][0]["data"][0]["SecuName"]);
$("#content").html(data["root"][0]["data"][0]["Content"]);
}
else {
$("#content").html("暂无具体内容!");
}
});
}
catch (ex) {
$("#content").html("暂无具体内容!");
}
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Hibernate多对多关系中间表有其他.. 下一篇Python 获得命令行参数的方法

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: