2017-09-01 60 views
3

此示例jquery的AJAX負載不是函數

<!DOCTYPE html> 
 
<html> 
 
<body> 
 
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> 
 
<div id="test"></div> 
 
<script> 
 
$(document).ready(() => { 
 
\t $('#test').load('doesntmatter'); 
 
}); 
 
</script> 
 
</body> 
 
</html>

似乎對我喜歡它是與爲ajax load function的例子。正如代碼片段可以告訴你的,它實際上會出錯

Uncaught TypeError: $(...).load is not a function 

我在做什麼錯?

回答

0

JQuery的格式錯誤:

$(document).ready(function() { 
     $('#test').load('doesntmatter'); 
    }); 

然後在目錄或添加頁面名稱,進入負載參數

  • 另外,還要確保你的腳本是最新的功能版本
+0

在相同的錯誤使用你的代碼的結果。 –

+0

刪除.load並添加'alert('test');'這是否工作?如果不是你的腳本文件沒有加載JS,但=>不是有效的語法,所以這也是一個錯誤。 – clearshot66

+0

是的,使用'alert'代替工作。 =>是[有效的javascript語法](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions)。 –

1

您的語法錯誤。

請試試這個

$(document).ready(function(){ 
    $("button").click(function(){ 
     $("#div1").load("demo_test.txt #p1"); 
    }); 
});