簡體   English   中英

jquery.get僅在Internet Explorer中工作

[英]jquery.get only working in Internet Explorer

我正在建立一個網站,我需要訪問一個名為friends.txt的文件並獲取第一個元素。

然后,我在文件夾名稱中使用它來顯示一些圖片。 問題是jquery.get似乎有安全限制,我只能讓它在Internet Explorer中工作。 我還應該做其他事情來讀取服務器端文件嗎?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
    $.get("friends.txt", function(data){
        var text = data.split("/");
        var p1 = text[0];
            var x = document.createElement("IMG");
            x.setAttribute("src", "../../Documents/dumpster_shit/FB/"+p1+"/0.jpg");
            x.setAttribute("class","democlass")
            document.body.appendChild(x);
        }
    });
</script>

進行較小的更正(我刪除了多余的花括號),您的代碼就可以正常運行,就像在Chrome上一樣。

證明: http ://sam.nipl.net/test-friends.html,http: //sam.nipl.net/friends.txt

您是否要使用file:/// URL在自己的計算機上進行本地測試? 某些瀏覽器具有安全功能,以防止您使用ajax訪問本地文件。 對於Chrome,您需要使用以下命令行選項:

chrome --allow-file-access-from-files

您也可以嘗試在本地Web服務器上運行測試站點。

暫無
暫無

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

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