search

Home  >  Q&A  >  body text

jquery - How to write Laravel routing so that it can correctly respond to Ajax requests initiated by the front end in GET mode?

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){
    
                }
            });
        });
某草草某草草2777 days ago774

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-16 16:49:02

    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) {
                }
            });
            
            

    reply
    0
  • 迷茫

    迷茫2017-05-16 16:49:02

    routing

    Route::get('aaa/bbb')
    

    Controller in

    $arg1=$_GET['arg1'];

    reply
    0
  • Cancelreply