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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用