2017-08-02 44 views
-2
$.ajax({ 
    url:"test.html", 
    cache: false, 
    success: function(html){ 
     $("#results").append(html); 
    }, 
});  

最後一個鍵值對(success:function)末尾有一個尾隨逗號。我想知道是否Internet Explorer尾隨逗號。 代碼在Google Chrome和Mozilla Firefox中正常工作。 但在某些情況下,我收到JavaScript錯誤「預期標識符,字符串或數字」。 我想知道的是,尾隨逗號是導致此錯誤的原因。對象中的尾隨逗號

+0

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas#Browser_compatibility – yuriy636

+3

刪除它,看看錯誤消失。 – 2017-08-02 16:32:08

回答

1

這與Ajax完全沒有關係。它完全是關於對象字面量的:

{ 
    url:"test.html", 
    cache: false, 
    success: function(html){ 
    $("#results").append(html); 
    }, 
} 

直到ES5,對象文本中的尾隨逗號被禁止。

Internet Explorer在版本9之前不支持它們(並且可能只有當Doctype觸發標準模式時)。

reference