JQurey中的getJSON方法请求的接口有错误时的处理方法
2012-02-08 15:52
615 查看
在用JQurey中的getJSON方法时,通常会碰到请求的接口有错误的情况发生,这时我们可以用下面的方法来做处理,代码如下:
<script type="text/javascript">
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("暂无具体内容!");
}
}
</script>
<script type="text/javascript">
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("暂无具体内容!");
}
}
</script>
相关文章推荐
- android利用httpclient实现post、get请求restful接口进行json和form表单数据提交等公共方法类
- JQurey中getJSON方法错误回调方法
- Android 万能Get请求Json方法
- linux shell中curl 发送post请求json格式问题的处理方法
- get请求中文的处理方法
- Android网络框架-Volley(四) 使用get和post方法发送json请求
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
- ie下jquery.getJSON的缓存问题的处理方法
- HTTP协议中POST、GET、HEAD、PUT等请求方法以及一些常见错误
- ie下jquery.getJSON的缓存问题的处理方法
- 支付宝即时到账接口,异步回调post请求的接受,Jersey 处理post参数的方法
- c# https get请求 基础连接已关闭,接受时发生错误 解决方法
- Android网络框架-Volley(四) 使用get和post方法发送json请求
- ie下jquery.getJSON的缓存问题的处理方法
- HTTP协议中POST、GET、HEAD、PUT等请求方法以及一些常见错误(转载)
- C# winform端 通过HttpWebRequest进行post和get请求,数据格式为json,后台java端接收,其中有关传输特殊字符(\t,\r,',\n,n)等处理
- jquery使用$.getJson()跨域大数据量请求方法
- HTTP协议中POST、GET、HEAD、PUT等请求方法以及一些常见错误
- Datawindow通过Json接口实现数据操作时(三层)PHP5.2 json_encode时发现汉字转换成了\u表示的处理方法
- 带 参数 ajax请求(利用getjson方法按客户id来请求客户信息)