Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.ajax({
- url: '{{ URL::action('getLocation') }}',
- // ...
- });
- Route::post('/getLocation', array('as'=>'getLocation','uses'=>'FrontController@getLocation'));
- Route::post('getLocation',array(
- 'as'=>'getLocation','uses'=>'FrontController@getLocation')
- );
- {!! Form::open() !!}
- {!! Form::text('input-name',null,array('class'=>'form-control search-input','data-url'=> URL::route("getLocation") ))
- {!! Form::close() !!}
- $('.search-input').each(function(){
- $(this).on('change',function (e) {
- search(this)
- });
- });
- function search(self) {
- var query = $(self).val();
- $.ajax({
- url: $(self).attr('data-url'),
- type: 'post',
- data: {'q':query, '_token': $('input[name=_token]').val()},
- success: function(data){
- console.log(data);
- },
- error: function(data){
- // Not found
- }
- });
- }
- URL::action('FrontController@getLocation')
- URL::route('getLocation')
- // Add this in your filtes.php file (feel free to store where you like)
- View::composer('layouts.master', function($view) {
- $ajaxUrl = json_encode(array('url' => URL::action('getLocation')));
- $view->with('ajax', $ajaxUrl);
- });
- <script>var ajax = {{ $ajax or 'undefined' }}</script>
- // ajax.url
- console.log(ajax.url);
Add Comment
Please, Sign In to add comment