我正在使用数据表来显示记录并使用 laravel作为后端 在我的localhost中,它通常在datatable中显示数据。但是当我在宅基地跑步时,我有一个错误:
我的ajax中的“500(内部服务器错误)”
这里是我的json数据:
[{"id":11,"uid":null,"email":"muhghazaliakbar@live.com","username":"muhghazaliakbar","oauth_provider_id":null,"activated":1,"activation_code":null,"activated_at":"2015-05-31 03:54:29","last_login":null,"persist_code":null,"reset_password_code":null,"created_at":"2015-05-31 03:54:29","updated_at":"2015-05-31 03:54:29","deleted_at":null},{"id":12,"uid":null,"email":"nurindahsari@live.com","username":"nurindahsari","oauth_provider_id":null,"activated":1,"activation_code":null,"activated_at":"2015-05-31 13:50:57","last_login":null,"persist_code":null,"reset_password_code":null,"created_at":"2015-05-31 13:50:57","updated_at":"2015-05-31 13:50:57","deleted_at":null},{"id":15,"uid":"974422342576145","email":"tambahkancintadankurangibenci@hotmail.com","username":"tambahkancintadankurangibenci@hotmail.com","oauth_provider_id":1,"activated":1,"activation_code":null,"activated_at":null,"last_login":null,"persist_code":null,"reset_password_code":null,"created_at":"2015-05-31 17:30:13","updated_at":"2015-05-31 17:30:14","deleted_at":null}]
在这里我的剧本:
var UsersTable = function () {
var handleRecords = function () {
var grid = new Datatable();
var table = $("#frontend_users_table");
grid.init({
src: table,
onSuccess: function (grid) {
// execute some code after table records loaded
console.log(grid);
},
onError: function (grid) {
// execute some code on network or other general error
},
loadingMessage: 'Loading...',
dataTable: { // here you can define a typical datatable settings from http://datatables.net/usage/options
"bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
"lengthMenu": [
[10, 20, 50, 100, 150, -1],
[10, 20, 50, 100, 150, "All"] // change per page values here
],
"pageLength": 10, // default record count per page
"ajax": {
"url": globalUrl + "/users/frontend/all",// ajax source
"type": "GET"
},
"searchable": true,
"order": [
[1, "asc"]
]
}
});
};
return {
//main function to initiate the module
init: function () {
handleRecords();
}
};
} ();
这是我的服务器端代码
if(isset($_REQUEST["search_users"]) != '') {
$str = $_REQUEST["search_users"];
$userData = \PasangJob\Model\Frontend\User::where('username', 'LIKE', '%'.$str.'%')
->orWhere('email', 'LIKE', '%'.$str.'%')
->get();
} else {
$userData = \PasangJob\Model\Frontend\User::get();
return $userData;
}
$iTotalRecords = $userData->count();
$iDisplayLength = intval($_REQUEST['length']);
$iDisplayLength = $iDisplayLength < 0 ? $iTotalRecords : $iDisplayLength;
$iDisplayStart = intval($_REQUEST['start']);
$sEcho = intval($_REQUEST['draw']);
$records = array();
$records["data"] = array();
$end = $iDisplayStart + $iDisplayLength;
$end = $end > $iTotalRecords ? $iTotalRecords : $end;
for($i = $iDisplayStart; $i < $end; $i++) {
if ($userData[$i]->activated == '1')
{
$status = "<span class=\"label label-success label-sm\">Activated<span>";
} else
{
$status = "<span class=\"label label-danger label-sm\">Not Activated<span>";
}
$records["data"][] = array(
$userData[$i]->id,
$userData[$i]->username,
$userData[$i]->email,
$userData[$i]->roles->first()->display_name,
$status,
$userData[$i]->last_login,
"<a id=\"view-user\" href=\"".route('pasangjob.users.frontend.show', $id = $userData[$i]->id)."\" class=\"btn default btn-xs green-stripe\">View</a>"
);
}
$records["draw"] = $sEcho;
$records["recordsTotal"] = $iTotalRecords;
$records["recordsFiltered"] = $iTotalRecords;
return response()->json($records);