duannaxin9975 2015-08-27 10:50
浏览 48
已采纳

404找不到错误Ajax Laravel 5.1

I'm trying to get the subcategories on the base of a category in laravel 5.1 but first it was giving me an error of '500 internal server error' but I include

RewriteBase /

in my .htaccess file and nos it is giving me en error of 'not found 404 error'. I'm using a virtual host and Form facade which automatically includes 'csrf token', so I think it's not the problem of 'csrf' token problem. Can any one help in this regard?????

This is my route file:

// Admins Tasks

Route::group(['middleware'=>'admin'], function() {

//Route::resource('/showcategoreis/{$id}', 'AdminHelperContooler@filterSubcat');
Route::get('/ajax-subcat/{id}', function(){
    return "mkj";
   $cat_id = Input::get('cat_id');
   $subcategories = Subcategory::where('category_id', '=', $cat_id)->get();

   return Response::json($subcategories);
});

Route::resource('/admin', 'Admin\AdminController');
Route::resource('/user', 'UserController');
Route::resource('/province', 'ProvinceController');
Route::resource('/city', 'CityController');

Route::resource('/category', 'CategoryController');


Route::resource('/subcategory', 'SubcategoryController');
Route::resource('/brand', 'BrandController');
Route::resource('/model', 'BModelController');
});

view.blade file

@extends('admin.layout.master')

@section('title')
Add New Brand
@endsection

@section('content')
<div class="col-md-6 col-md-offset-3">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">Add New Brand</h3>
        </div>
        <div class="panel-body">
            {!! Form::open(['files'=>true, 'url' => '']) !!}

                <div class="form-group">
                    {!! Form::label('brand', 'Brand Title') !!}
                    {!! Form::text('brand', null, ['class' => 'form-control']) !!}
                    <small class="text-danger">{{ $errors->first('brand') }}</small>
                </div> {{-- brand --}}

                <div class="form-group">
                     {!! Form::label('category_id', 'Category') !!}
                     {!! Form::select('category_id', $categories, $options = ['id'=>'category_id', 'class' => 'form-control']) !!}
                     <small class="text-danger">{{ $errors->first('category_id') }}</small>
                 </div> {{-- category_id --}}

                 <div class="form-group">
                     {{-- {!! Form::label('subcategory_id', 'Subcategory') !!} --}}
                     {{-- {!! Form::select('subcategory_id', $subcategories, $options = [ 'id'=>'subcategory', 'class' => 'form-control']) !!} --}}
                     {{-- <small class="text-danger">{{ $errors->first('subcategory_id') }}</small> --}}
                     <label for="">Subcategories</label>
                     <select name="subcategory" id="subcategory">
                        <option value=""></option>
                     </select>  
                 </div> {{-- subcategory_id --}}

                <hr>
                <div class="btn-group pull-left">
                    {!! Form::submit('Add', ['class' => 'btn btn-primary', 'style'=>'margin-right:5px']) !!}
                    {!! HTML::link(action('BrandController@index'), 'Cancel', ['class' => 'btn btn-warning']) !!}
                </div>

            {!! Form::close() !!}
        </div>
    </div>
</div>

@endsection 

{{-- JS for AJAX --}}

    <script type="text/javascript">
        $(document).ready(function(){
            $('#category_id').on('change', function(e){
                console.log(e);

                var cat_id = e.target.value;

                //Ajax
                $.ajax({
                    type: 'get',
                    // url: 'http://localhost/property-project/public/index.php/ajax-subcat?cat_id'+cat_id,
                    // url: 'http://www.laravelproperty.com/brand/create/ajax-subcat?cat_id='+cat_id,
                    url: '/ajax-subcat?cat_id='+cat_id,
                    scuccess: function(data){
                        console.log(data);
                    }
                });
                // $.get('/ajax-subcat?cat_id='+cat_id, function(data) {
                //  //scuccess data
                //  console.log(data);
                // });
            });
        });
    </script>

.htaccess file

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

virtual host file

<VirtualHost *:80>
    ServerAdmin m.khuramj@live.com
    ServerName laravelproperty.com
    ServerAlias www.laravelproperty.com

    DocumentRoot /var/www/property-project/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/property-project/public/>
        AllowOverride All
    </Directory>
</VirtualHost>

I've removed the changes in '.htaccess' and still getting the error and this is the error stack:

Sorry, the page you are looking for could not be found.

1/1
NotFoundHttpException in RouteCollection.php line 143:
in RouteCollection.php line 143
at RouteCollection->match(object(Request)) in Router.php line 746
at Router->findRoute(object(Request)) in Router.php line 655
at Router->dispatchToRoute(object(Request)) in Router.php line 631
at Router->dispatch(object(Request)) in Kernel.php line 236
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 54
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 122
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87
at Kernel->handle(object(Request)) in index.php line 54
  • 写回答

1条回答 默认 最新

  • douyan1972 2015-08-27 23:49
    关注

    The route you've defined is '/ajax-subcat/{id}' but the you're trying to call '/ajax-subcat?cat_id='+cat_id in your AJAX. Change your route to '/ajax-subcat' and that should at least fix your 404 error.

    Alternately, you could change your AJAX to call '/ajax-subcat/'+cat_id

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?