我有一個簡單的頁面,我需要加載HTML文件到一個DIV,但我總有404 NOT FOUND.load()在jQuery的方法給我404 - Not Found錯誤
我稱之爲一個文件demo_test.txt在我的JSP文件相同的文件夾,我需要這個文件加載到帶有ID =「DIV1」
這裏的DIV是代碼:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js">
</script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
// $("#div1").load("demo_test.txt");
$("#div1").load("demo_test.txt", function(responseText, statusText, xhr)
{
if(statusText == "success")
alert("Successfully loaded the content!");
if(statusText == "error")
alert("An error occurred: " + xhr.status + " - " + xhr.statusText);
});
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
您是否嘗試過使用的URL,瀏覽文件你期望找到它嗎? –
您是否在您的瀏覽器調試器的網絡檢查器選項卡中檢入了哪個文件正試圖加載?然後點擊右鍵並點擊「在新標籤中打開」? –
爲了達到此目的,文件必須與調用腳本的HTML頁面位於完全相同的目錄中。是這樣嗎? – fge