我在尝试升级的基于Laravel的网站上遇到了两个问题。
它使用DataTables进行了很多报道,我真的不想重写,但我不时会得到302(找到)响应而不是JSON。
这导致了问题二:当发生这种情况时,用户会被注销。
有没有人有什么可能导致这些问题的建议?
使用: Laravel 4.1.27 jQuery 1.8.3 PHP 5.5.19 DataTables 1.10.0
其中一个DataTables调用:
function makeMiscItemsTable(tableSelector, url) {
if (url === undefined) {
miscItemsTable = $(tableSelector).DataTable({
"fnRowCallback": function (nRow, aData, iDisplayIndex) {
$(nRow).children('.donation-id').html(['<a title="View/Edit" href="/inventory/donation/details/', aData['donation_id'], '">', aData['donation_id'], '</a>'].join(""));
// Apply stying to rows based on the item's status: received, recycled or sent/other
if (aData['status'] == 'sent') {
$(nRow).addClass('row-blue');
} else if (aData['status'] == 'recycled') {
$(nRow).addClass('row-red');
} else {
$(nRow).addClass('row-green');
}
},
"oLanguage": {
"sProcessing": "<img src='/assets/images/ajax_clock_small.gif'>",
"sSearch": ""
},
"bDeferRender": true,
"bProcessing": true,
"sAjaxSource": '/inventory/donation/misc_items',
"sPaginationType": "four_button",
"bRetrieve": true,
"aaSorting": [[1, "desc"]],
'aLengthMenu': [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'All']],
'iDisplayLength': 25,
'aoColumns': [
{
"mDataProp": null,
"sClass": "center-text",
"sDefaultContent": '<input type="checkbox" name="misc-item-select" class="misc-item-check" value="selected" false>'
},
{
"mDataProp": 'donation_id',
"sClass": 'donation-id'
},
{"mDataProp": 'description'},
{
"mDataProp": 'status',
"sClass": "hide"
},
{
"mDataProp": 'id',
"sClass": "hide misc-item-id"
}
],
"aoColumnDefs": [
{'bSortable': false,
'aTargets': [0]
}
]
});
} else {
miscItemsTable.ajax.url(url).load();
}
}
控制器代码:
public function get_misc_items($status = null)
{
$attributes = DonatedMiscItem::$datatable_attributes;
if ($status === null) {
$items = DonatedMiscItem::all($attributes);
} else {
$items = DonatedMiscItem::where('status', $status)->get($attributes);
}
$results = array();
$count = $items->count();
foreach ($items as $item) {
$results[] = $item['original'];
}
return Response::json(array('aaData' => $results, 'iTotalRecords' => $count, 'iTotalDisplayRecords' => $count));
}
路线:
Route::get('donation/misc_items/{status?}', 'DonationController@get_misc_items');
名为:
的网址site.com/inventory/donation/misc_items?_=1425080932188
答案 0 :(得分:0)
302 respose是一个重定向,可能是从应用程序会话超时触发的,这就是用户同时注销的原因。检查位置标题以查找重定向的实际URL是否为登录页面。