簡體   English   中英

jQuery load()https http

[英]jquery load() https http

我在使用jQuery load()函數從另一個頁面獲取元素時遇到問題。 我只能將客戶端腳本添加到頁面A( https://landing.pkr.com/en/bonus/ ),並且試圖從頁面B( http://letsplay.pkr.com )中獲取元素/ en / ),我無法對其進行編輯。

我在A頁上有以下代碼:

$('#playerNumber').load('https://letsplay.pkr.com/en/ div.players.roundContainerBorderNone h2');

頁面A在https協議上運行。 頁面B在http和https上都運行。

我最初的問題是我試圖從B頁中獲取該元素。由於協議沖突,代碼無法正常工作,但是我將協議更改為https,這基本上解決了問題。

唯一的例外是當我嘗試使用隱身窗口在Chrome中查看頁面時。 由於某種原因,代碼無法正常工作。 有人可以向我解釋為什么會這樣,是否會引起人們的關注? 這個問題有解決方案嗎?

非常感謝

---附加評論--------------------------------------------- ---------

經過進一步調查,結果發現頁面B不支持https。 這是否意味着該問題無法解決?

請嘗試這個。

$.support.cors = true;
$.ajax({
    type: 'GET',
    dataType: "text",
    crossDomain: true,
    url: "http://letsplay.pkr.com/en/ div.players.roundContainerBorderNone h2",
    success: function (responseData, textStatus, jqXHR) {
        var _data = JSON.parse(
            responseData.replace(
                '{"AuthenticateUserResult":"', ''
            ).replace('}"}', '}')
        );
        $('#playerNumber').html(_data);
    },
    error: function (responseData, textStatus, errorThrown) {
        alert('POST failed.');
    }
});

問題似乎是跨域訪問。 您可以從url中省略該方案,默認情況下,瀏覽器采用當前頁面正在使用的方案。

試試以下內容:

$('#playerNumber').load('letsplay.pkr.com/en/ div.players.roundContainerBorderNone h2');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM