dtm37893 2018-08-16 06:53
浏览 67

我的Ajax请求只发送一次

I have an ajax request for getting the purchased list of a user. I thought it was perfectly working because it returns the data that I need. But when I click the other user it seems the ajax request only send a request once. Becuase the data is the same, and when I look at the network tool of chrome, there is no another request was send.

This is my current Ajax request.

var purchased_list;
// $('#student_profile_purchased_item_list_tab').click(function(){
    function createTablePurchasedList(id){
        console.log("Start, student:"+id);
            purchased_list= $('#purchased_item_list_table').DataTable({
                // "processing": true,
                // "paging":   false,
                // "ordering": true,
                "ajax": {
                    url:'{{ route("student_item_list") }}?student_id='+id,
                    cache: true,
                    dataSrc: "",
                },
                columnDefs: [
                    {
                        className: "dt-center",
                        targets: [0],
                    },
                ],
                "columns": [
                    {
                        data: "date_purchased"
                    },
                    {
                        data: "product_status_id",
                        render: function(data, type, row){
                            switch(data){
                                case 2:
                                    return 'Purchased';
                                case 3:
                                    return '<p style="color:red;">Consumed</p>';
                                case 6:
                                    return '<p style="color:green;">Transferred</p>';
                            }
                        }
                    },
                    {
                        data: "name",
                        render: function(data, type, row){
                            return data;
                        }
                    },
                ]
            });
        console.log("End, student:"+id);
    }
// });

Tab

<li><a href="#student_profile_purchased_item_list" data-toggle="tab" id="student_profile_purchased_item_list_tab">Purchased Item List</a></li>

Datatable

<div class="tab-pane fade in" id="student_profile_purchased_item_list">
    <div style="position:relative;">
        <div class="other_content_header">
            Item List
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <table width="100%" class="responsive table table-striped table-bordered table-hover purchase-item-table" id="purchased_item_list_table" style="font-size:12px; text-align:center;">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Item Status</th>
                        <th>Product Name</th>
                        {{-- <th>Quantity</th> --}}
                        {{-- <th> </th> --}}
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>

every time I click a user the console.log result changes, At first I thought the ID is not changing when I click another user. But when I do the console log the result changes.

Hope someone can help me solve my problem.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?