jquery - How to write Laravel routing so that it can correctly respond to Ajax requests initiated by the front end in GET mode?
某草草
某草草 2017-05-16 16:47:02
0
2
772

jquery's ajax method, for GET requests, will splice the url and query parameters into http://xxx.xxx/aaa/bbb?arg1=ddd to initiate the request.

I define a route like Route::get('aaa/bbb/{arg1}'). The request that this route can recognize is http://xxx.xxx/aaa/bbb/ddd.

For such a problem, how should laravel's routing be written to correctly respond to the front-end AJAX request?

Post the solved code memo:
Route:
Route::get('getProjectInfoByAPI/{url?}', 'ProjectController@getProjectInfo');
front end:

       $.ajax({
                url: 'getProjectInfoByAPI',
                type: 'GET',
                data: {
                    url: xxx,
                },
                dataType: 'json',
                success: function(response){
    
                }
            });
        });
某草草
某草草

reply all(2)
伊谢尔伦

Route::get('/aaa/bbb/{arg1?}','UserController@arg1');

$.ajax({

         type: 'get',
         url: '/aaa/bbb',
         data: {'arg1': 'ddd'},
         headers: {'X-CSRF-Token': $('meta[name=csrf-token]').attr('content')},
         dataType: 'json',
         success: function (msg) {
            }
        });
        
        
迷茫

routing

Route::get('aaa/bbb')

Controller in

$arg1=$_GET['arg1'];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template