php - 500 (Internal Server Error) ajax get datatable laravel -
i'm using datatable showing record , using laravel backend in localhost show data in datatable. when run in homestead, have error:
"500 (internal server error)" in ajax
here json data:
[{"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}]
and here script:
var userstable = function () { var handlerecords = function () { var grid = new datatable(); var table = $("#frontend_users_table"); grid.init({ src: table, onsuccess: function (grid) { // execute code after table records loaded console.log(grid); }, onerror: function (grid) { // execute code on network or other general error }, loadingmessage: 'loading...', datatable: { // here can define typical datatable settings 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 initiate module init: function () { handlerecords(); } }; } ();
here server side code
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);
Comments
Post a Comment