2012-01-27 64 views
7

我很困惑我只在IE中使用HTTPS Ajax調用時遇到的問題。 IE似乎認爲我正在提出跨域請求,但我不是。下面的代碼是從https://mydomain/customer_profile.php的頁面叫做:HTTPS Ajax請求在IE中的問題(不是跨域)

$.ajax({ 
    type: 'post', 
    url: 'https://mydomain/ajax/retrieve_transaction_details.php', 
    data: /* my data is here */, 
    success: function(response){ 
     // do something with the response 
    }, 
    error: function (xhr, ajaxOptions, thrownError){ 
     alert(xhr.status); 
     alert(thrownError); 
    } 
}); 

這個請求工作得很好,除了IE瀏覽器的每一個。在IE中,錯誤函數返回「錯誤:訪問被拒絕」。就像我所說的,我完全沉迷於此,所以任何見解或想法都會很棒。

+1

嘗試不使用「https:// mydomain」。因此,請嘗試將網址設置爲「/ajax/retrieve_transaction_details.php」。 – 2012-01-27 16:18:12

+0

我試過這個。無論出於何種原因,如果我沒有指定絕對路徑,其他瀏覽器就會嘗試通過HTTP發出請求,從而也將其打破。 – 2012-01-27 16:20:10

+0

也許添加一個檢查瀏覽器,如果他們使用IE瀏覽器兼容性,如果他們使用任何其他瀏覽器,然後將其轉發到您已經有工作的代碼將遵循路徑。 – HenryGuy 2012-01-27 16:47:22

回答

3

我猜你是使用HTML的部分內<base>標籤;對?

如果它指向http,而不是https,這會破壞IE

+0

哇,這其實就是它。我完全忘了我在標題模板中拋出了該標籤。有趣的是,它只能在IE中打破它,但我想這是IE的雅。謝謝! – 2012-01-31 19:45:56

2

嘗試這樣的設置跨域到真正在你的要求:

$.ajax({ 
    type: 'post', 
    url: 'https://mydomain/ajax/retrieve_transaction_details.php', 
    data: /* my data is here */, 
    crossDomain: true, 
    success: function(response){ 
     // do something with the response 
    }, 
    error: function (xhr, ajaxOptions, thrownError){ 
     alert(xhr.status); 
     alert(thrownError); 
    } 
}); 

這應該讓你做出的要求,無論它是跨域與否。

+0

嗯,這將錯誤更改爲「無運輸」。有趣。 – 2012-01-27 16:54:58

+0

看看這篇文章:http://stackoverflow.com/questions/5241088/jquery-call-to-webservice-returns-no-transport-error – 2012-01-27 16:56:35