处理这种情况的一种方法是检测出进行跨域AJAX调用并尝试更改协议时固有的失败页面加载。 AJAX和页面转换不会使用这种方法,但是,它可以防止您必须使用data-ajax=false
属性乱丢您的网站。这可以在两个方向上工作(即从HTTPS到HTTPS)。
$(document).bind("pageloadfailed", function (event, data) {
// Let the framework know we're going to handle things.
event.preventDefault();
// Attempt to change protocols
window.location.href = data.absUrl.indexOf('https://') > -1 ?
data.absUrl.replace('https://', 'http://') :
data.absUrl.replace('http://', 'https://');
// At some point, if the load fails, either in this
// callback, or through some other async means, call
// reject like this:
data.deferred.reject(data.absUrl, data.options);
});
这不是完美的解决方案,因为它会导致两个请求:1st到https协议 - 发送表单数据但取消(无响应),第二--http - 产生响应但不发送数据。 FCK – Luciuz