3

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 ?

<!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>

1 Answer 1

3

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.

*Generally true, there are ways around this.

https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, you are very correct, but according to the example here jsfiddle.net/wenyi/e3nk137y/13 ( from: bootstrap-table.wenzhixin.net.cn/examples) my jsfiddle example should also work but it isn't jsfiddle.net/gsz6kkzq. It is using the data object to load fields
I made some tweaks and got it working. I removed data-toggle="table" and changed $("#table").bootstrapTable('refresh', { data: d }); to this: $("#table").bootstrapTable({ data: d }); jsfiddle.net/gsz6kkzq/1
Yes, Thanks you. wonder why the first one doesn't work. Maybe browser issue or something. Thanks anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.