无法使用简单的 jQuery 数据表加载外部 URL
我在 Eclipse 中创建了一个简单的静态 Web 项目。我将 jquery.js 和 jquery.dataTables.js 下载到我的 WebContent 文件夹中。然后我创建了一个 index.html 页面,如下所示:
<!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 的 JSON 响应: 8080/myProj/listLogs?messageId=33333333333 应如下所示:
{
"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 甚至没有被调用。不知道为什么。
I created a simple static web project in Eclipse. I downloaded jquery.js and jquery.dataTables.js into my WebContent folder. Then I created a index.html page which looks like this:
<!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>
The JSON response from http://localhost:8080/myProj/listLogs?messageId=33333333333 should look like:
{
"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]"
],
...
}
But when I open the index.html in my firefox, nothing gets loaded. I do see this on the page though:
stuff
stuff
Loading...
Showing 0 to 0 of 0 entries
PreviousNext
My JSON URL was not even invoked. Not sure why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我找到了答案:
http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
我的 JSON 端点位于不同的端口上:)
Think I found the answer:
http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
My JSON endpoint is on a different port :)