0
我在Eclipse中創建了一個簡單的靜態Web項目。我將jquery.js和jquery.dataTables.js下載到我的WebContent文件夾中。然後,我創建了一個index.html頁面,看起來像這樣:無法使用簡單的jQuery數據表加載外部URL
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable({
"sAjaxSource" : 'http://localhost:8080/myProj/listLogs?messageId=33333333333'
});
});
</script>
<title>Insert title here</title>
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0" class="display"
id="example">
<thead>
<tr>
<th>stuff</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th>stuff</th>
</tr>
</tfoot>
</table>
</body>
</html>
從http://localhost:8080/myProj/listLogs?messageId=33333333333 JSON響應應該是這樣的:
{
"aaData": [
[
"This is a NEW message"
],
[
"Parsing message with messageId = 33333333333 and eventType = CREATE"
],
[
"Start running workflow with 4 actions"
],
[
"Updating entitlement for event: [33333333333:CREATE]"
],
... }
但是當我在我的Firefox中打開index.html時,沒有任何東西被加載。我看到這雖然在頁面上:
stuff
stuff
Loading...
Showing 0 to 0 of 0 entries
PreviousNext
我的JSON URL甚至沒有調用。不知道爲什麼。
使用http://JSONLint.com它是無效 – Devjosh 2012-02-09 05:29:39
只是做驗證您的JSON 。這是有效的。正如我所說的,URL甚至沒有被調用。我可以通過服務器端的監控來判斷。 – scabbage 2012-02-09 05:34:58
我會建議你看看firebug控制檯或XHR請求從XHR標籤下的網絡面板的firefox,看看你的URL調用是否導致一些錯誤,如500內部服務器錯誤或404錯誤,這將有助於你,並檢查是否pat()是正確的 – Devjosh 2012-02-09 05:37:51