我试图从HTTPS网站到HTTP端点进行jquery Ajax调用。
我得到的是#34;混合内容"错误:
Mixed Content: The page at 'https://...' was loaded over HTTPS,
but requested an insecure XMLHttpRequest endpoint 'http://...'.
This request has been blocked; the content must be served over HTTPS.
问题是我对Ajax事件的回调'完成'虽然根据jquery页面(https://api.jquery.com/Ajax_Events/):
,但不会触发complete (Local Event)
This event is called regardless of if the request was successful, or not.
You will always receive a complete callback, even for synchronous requests.
这是我的代码:
$.ajax({
type: "POST",
url: url,
data: data,
complete: function (results) {
// Stuff in here is not executed on "Mixed Content" error
}
});
还有其他方法来捕获错误吗?阿贾克斯似乎没有能力。
修改 我知道这个问题:HTTP Ajax Request via HTTPS Page
我的问题不是"为什么会发生错误",我期待它发生。我的问题是我怎样才能捕捉到这种类型的错误,因为jQuery已经完成了'事件失败。