Guest User

Untitled

a guest
Oct 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. $.ajax({
  2. url: '{{ URL::action('getLocation') }}',
  3. // ...
  4. });
  5.  
  6. Route::post('/getLocation', array('as'=>'getLocation','uses'=>'FrontController@getLocation'));
  7.  
  8. Route::post('getLocation',array(
  9. 'as'=>'getLocation','uses'=>'FrontController@getLocation')
  10. );
  11.  
  12. {!! Form::open() !!}
  13. {!! Form::text('input-name',null,array('class'=>'form-control search-input','data-url'=> URL::route("getLocation") ))
  14. {!! Form::close() !!}
  15.  
  16. $('.search-input').each(function(){
  17. $(this).on('change',function (e) {
  18. search(this)
  19. });
  20. });
  21.  
  22. function search(self) {
  23. var query = $(self).val();
  24. $.ajax({
  25. url: $(self).attr('data-url'),
  26. type: 'post',
  27. data: {'q':query, '_token': $('input[name=_token]').val()},
  28. success: function(data){
  29. console.log(data);
  30. },
  31. error: function(data){
  32. // Not found
  33. }
  34. });
  35. }
  36.  
  37. URL::action('FrontController@getLocation')
  38.  
  39. URL::route('getLocation')
  40.  
  41. // Add this in your filtes.php file (feel free to store where you like)
  42. View::composer('layouts.master', function($view) {
  43. $ajaxUrl = json_encode(array('url' => URL::action('getLocation')));
  44. $view->with('ajax', $ajaxUrl);
  45. });
  46.  
  47. <script>var ajax = {{ $ajax or 'undefined' }}</script>
  48.  
  49. // ajax.url
  50. console.log(ajax.url);
Add Comment
Please, Sign In to add comment