jQuery(ajax)重定向到另一个域 [英] jquery (ajax) redirect to another domain
本文介绍了jQuery(ajax)重定向到另一个域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下格式的jquery json请求:
I have the jquery json request in the following format:
JSON请求:
$.getJSON('http://xyz.com',function(result) {});
如果请求失败(服务器未响应),我如何重定向到另一个域.例如"http://zxy.com".(我们在另一台服务器上维护相同的代码)
If the request fails(server not responds), how do i redirect to another domain. for example "http://zxy.com".(we maintaining the same code in another server)
推荐答案
您尝试过吗?
function addImage(item) {
$("<img/>").attr("src", item.media.m).appendTo("#images");
}
var jqxhr = $.getJSON("http://xyz.com",function(data) {
$.each(data.items, function(i,item){ //sample
addImage(item);
})
.error(function() {
var jqxhrFailover = $.getJSON("http://zzz.com", function(data) {
$.each(data.items, function(i,item){ //sample
addImage(item);
}).error(function(){ alert('both failed!'); });
这篇关于jQuery(ajax)重定向到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文