簡體   English   中英

文檔元素之后的垃圾Firefox錯誤使用JQuery Get加載內容

[英]junk after document element Firefox Error Loading Content With JQuery Get

我有一個頁面(遺憾的是在登錄系統后面),它在文章列表的左側基本上有一個導航欄,當你點擊一篇文章時,它會從存儲在服務器上的.inc文件加載內容,使用提供的文件路徑。

這適用於Google Chrome。

但是,在Firefox上,當頁面加載時,我得到這個奇怪的javascript錯誤:

“文檔元素之后的垃圾” - 當我單擊錯誤時,它會將我從第一篇文章的第2行加載。

我來給你看一些代碼。

這是頁面加載完成后運行的最后一個JS函數,其目的是加載初始文章。

function initialise_family_center_page() 
{
    if (current_element_id == "" || current_element_id == "family_center_general_info") //If this is the first article to be loaded
    {
        //Get the file path of the inc file to load

        var content_directory = file path....;

        jQuery.get(content_directory, function(data) 
        {
            $('#family_center_main_content').html(data);    //Load the content
        }); 
    }   
}

正在加載的.inc文件中的內容如下:

<p>Some text</p>

<p>Some text</p>

此時值得一提的是,在Chrome和Firefox中,內容會加載。 但是在firefox中,由於JS錯誤,您無法再使用頁面的其余部分,因為JS已停止工作。

有趣的是,我通過Google搜索問題發現,如果我將文件的內容更改為:

<html>
    <p>Some Text</p>

    <p>Some Text</p>
</html>

然后錯誤沒有出現,頁面工作(直到你加載沒有標簽的下一個內容文件。

但是,這不是一個合適的修復,因為有成千上萬的文件。

有人可以幫忙嗎?

我有同樣的問題。 我創建了一個基頁,點擊nav元素觸發$.ajax()獲取一個inc文件,該文件將填充頁面上的主div - 如下所示:

$(document).ready(function(){
  // Set trigger and container variables
  var trigger = $('nav.primary ul li a'),
      container = $('#se-main');
  trigger.on('click', function(){
    // Set click target from data attribute
    target = this.target;
    $.ajax({
        url:'../inc/'+target + '.inc',
        success: function(data){
            // Load target page into container
            container.html(data);
        },
        dataType: "text" // this seems to be ignored in Firefox
    });
// snip other stuff
});

除非我編輯了INC文件並將文本包裝在<html></html>否則Firefox控制台始終記錄“文檔元素之后的垃圾”錯誤。 (頁面內容仍然更新,因此用戶不會被它阻止)。

要解決此問題:將inc添加到apache mime.types配置文件中的text/html行。

找到行

text/html                   html htm

改成

text/html                   html htm inc

然后重啟apache。

這對我有用。

默認文件位置:

Linux/etc/mime.types ;

WAMP[wampdir]\\bin\\apache\\[apacheversion]\\conf\\mime.types

XAMPP[xamppdir]\\apache\\conf\\mime.types

[wampdir]在哪里安裝WAMP / XAMPP,而[apacheversion]是WAMP正在使用的apache版本。

如果您無權訪問mime.types文件,或者您正在共享主機上運行,​​則此解決方案無效。

在這種情況下 - 假設您有權訪問.htaccess - 將以下內容添加到.htaccess可能會有效 -

AddType text/html .html .htm .inc

暫無
暫無

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

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