我有一個uri傳遞給我一個休息電話,這是一個重定向url,我希望能夠攔截調用以獲得重定向'位置'的標題。如何攔截並獲取重定向URL的位置標題?
以下代碼對位置標題返回null。執行這個客戶端的正確方法是什麼?
$(document).ready(function() {
$.ajax({
url: 'http://myserver.com/redirect?token=AAAnY13Y-76LZ4zXDOd', // obviously not cross domain and contains redirect location to a youtube link to embed in my page, http://www.youtube.com/embed/bl2j345-xy
data: {
something: 'someotherthing'
},
complete: function (request, status) {
var location = request.getResponseHeader("Location"); // this is null...it shows up in Fiddler as http://www.myotherserver.com in the Location Header
},
error: function (request, error) {
alert(request.responseText);
}
});
});
[如何在jQuery Ajax調用後管理重定向請求](http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery- ajax-call)還有相關:http://stackoverflow.com/q/282429/995876 – Esailija 2012-08-10 22:29:21
我不確定是否只是爲我而是'status' ='error'。這可能是你沒有迴應標題的原因嗎? – Nope 2012-08-10 22:34:49
@FrançoisWahl:的確如此,我剛查過,狀態是錯誤的。它在工作之前,但絕對錯誤,但request.responseText是空白。 – JaJ 2012-08-10 22:51:36