twitter-bootstrap 如何正确使用 Bootstrap 表 data-url 属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43565815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to correctly use Bootstrap table data-url property?
提问by Syed Ahmed Jamil
I am trying to figure out how to use the data-url property of Bootstrap table Here is my code. I have added all the necessary CSS/JS files and referenced a correct JSON form file in the the data-url property but still it ain't showing any results. What am I missing here ?
我想弄清楚如何使用 Bootstrap 表的 data-url 属性这是我的代码。我已经添加了所有必要的 CSS/JS 文件并在 data-url 属性中引用了一个正确的 JSON 表单文件,但它仍然没有显示任何结果。我在这里错过了什么?
<!doctype html>
<html lang="en">
<head>
<!-- Required CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.css">
</head>
<body>
<table class ="table table-hover" id ="table" data-toggle="table" data-url="https://raw.githubusercontent.com/wenzhixin/bootstrap-table-examples/master/json/data1.json">
<thead>
<tr>
<th data-field="id">Item ID</th>
<th data-field="name">Item Name</th>
<th data-field="price">Item Price</th>
</tr>
</thead>
</table>
</body>
<!-- Required js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.js"></script>
<script>
$(table).bootstrapTable('refresh', {
url: 'https://raw.githubusercontent.com/wenzhixin/bootstrap-table-examples/master/json/data1.json'
});
</script>
</html>
回答by NovaPenguin
Look in the network tab in your browser debugger. Most likely you're getting a 400 error because of the Same-origin Policy. The browser can't* request content from a different domain than the one it's hosted on.
查看浏览器调试器中的网络选项卡。由于同源策略,您很可能会收到 400 错误。浏览器不能*请求来自与它托管的域不同的域的内容。
*Generally true, there are ways around this.
*大体上是正确的,有办法解决这个问题。
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

