Javascript 我的Ajax请求只发送一次
我有一个ajax请求,用于获取用户的购买列表。我认为它工作得很好,因为它返回了我需要的数据。但是当我单击其他用户时,ajax请求似乎只发送一次请求。因为数据是相同的,当我看chrome的网络工具时,没有发送另一个请求 这是我当前的Ajax请求Javascript 我的Ajax请求只发送一次,javascript,php,ajax,datatable,Javascript,Php,Ajax,Datatable,我有一个ajax请求,用于获取用户的购买列表。我认为它工作得很好,因为它返回了我需要的数据。但是当我单击其他用户时,ajax请求似乎只发送一次请求。因为数据是相同的,当我看chrome的网络工具时,没有发送另一个请求 这是我当前的Ajax请求 var purchased_list; // $('#student_profile_purchased_item_list_tab').click(function(){ function createTablePurchasedList(id)
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);
}
// });
var采购清单;
//$(“#学生#个人资料"购买的"物品"列表"选项卡)。单击(函数(){
函数createTablePurchasedList(id){
console.log(“开始,学生:+id”);
采购物品清单=$(“#采购物品清单表格”)。数据表({
//“处理”:对,
//“分页”:false,
//“排序”:正确,
“ajax”:{
url:“{route(“student_item_list”)}}?student_id=”+id,
是的,
dataSrc:“”,
},
columnDefs:[
{
类名:“dt中心”,
目标:[0],
},
],
“栏目”:[
{
数据:“购买日期”
},
{
数据:“产品状态标识”,
呈现:函数(数据、类型、行){
交换机(数据){
案例2:
返回“已购买”;
案例3:
返回已消费的“
标签
数据表
<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>
项目表
日期
项目状态
品名
{{--数量--}
{{-- --}}
每次我单击一个用户时,console.log结果都会更改,起初我认为当我单击另一个用户时,ID不会更改。但是当我做控制台日志时,结果会改变
希望有人能帮我解决我的问题。您的代码不足以解决问题,也许还可以显示html代码?为什么在ajax中使用
cache:true
?@RainDev删除请求中不必要的参数。但当我删除缓存时,真正的ht结果是same@ToniLatenz你是什么意思?我使用datatable显示mt ajax请求返回的数据。
<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>