bgultekin / laravel4-datatables-package

Server-side handler of DataTables Jquery Plugin for Laravel 4
267 stars 108 forks source link

Ajax problem #177

Closed Dragi4 closed 9 years ago

Dragi4 commented 9 years ago

Hi,

I am using Laravel 5.3.22, datatables 1.10.4 and this package. And I get http://gentaurshop.com/admin/admin/searchAjax?draw=1&columns%5B0%5D%5Bdata%…art=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1417610326089

I've read about this error here http://datatables.net/tn/7 , but couldn't solve the problem.

My routes
Route::get('/admin/searchAjax', array('as' => 'searchAjax', 'uses' => 'PublicController@searchAjax'));
Controller
$result = $search->datatables(Input::get('search'), 50);
return Datatables::of($result)->make();
Model
try{
$results = DB::table('table')
    ->join('table2', 'table.product_id','=','table2.product_id')
    ->where('table.product_name', 'LIKE', "%$term%")
    ->orWhere('table.product_cat_number', 'LIKE', "%$term%")
    ->select('table.product_id', 'table.product_url','table.product_name', 'table2.product_quantity', 'table2.product_price_sell', 'table.product_cat_number');
}
    catch(exception $e) {
        //error
}

    return $results;

Any ideas what I'm doing wrong? Can the problem be the exception? Thanks in advance.

yajra commented 9 years ago

Your route was not found... /admin/admin? check your URL. I think it should be http://gentaurshop.com/admin/searchAjax?draw=1&columns%5B0%5D%5Bdata%25%E2%80%A6art=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1417610326089. But there are still some errors but the URL is now correct. ^_^

Dragi4 commented 9 years ago

Thanks for the reply. I found this error while writing the post and changed the URL to correct URL and now the error is http://gentaurshop.com/admin/searchAjax?draw=1&columns%5B0%5D%5Bdata%…art=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1417610326089 So what ore the other errors?

yajra commented 9 years ago

On your controller, you are expecting a term parameter and you haven't passed any value which causes an error on trim function. Also check your routes and make sure you add the parameters as indicated in your function.

public function datatables($term,$paginate = NULL){
        $term = trim($term);
``
Dragi4 commented 9 years ago

Thanks so much, everything was passed correctly, but I was trying to trim an array in model $term = trim($term); Thanks again and have a nice day.