Help in laravel 5 and ajax. Get a value from the database

3

I want that in my view, when selecting something in my dropdown, I execute a method that I have in my controller, it performs another function (query) in my model, which takes a data (int) from a table . I have an error when debugging with chrome, I leave the link of the photo I'm using ajax, in which I'm not very expert in case they can help me out or tell me what I'm doing wrong. Another data my dropdown is inside a form, so I have seen some examples with form with Post which does not help me, since what I want to do is client-side. Since a user will be doing that.

Script

   $("#sociedad").change(function(){

      $.get("imp/"+event.target.value+"",function(response, sociedad){
          console.log(response);
      });
 });

Routes

Route::resource('venta','VentasController'); 
Route::get('imp/{id}',  'VentasController@getIva');

View and form

<div class="form-group">                                
{!!Form::select('msocod_id',['' => '- Seleccione una sociedad -'] +$soci,null, ['class' => 'form-control','id'=>'sociedad', 'name'=>'sociedad'])!!} 
</div>

Form

@extends('layouts.principal')
@section('content')

@include('alerts.request')
{!!Form::open(['route'=>'venta.store','method'=>'POST'])!!} 

@include('venta.forms.venta')

{!!Form::close()!!}
@section('script')
{!!Html::script('js/script.js')!!}
@stop
@stop
    
asked by Andrés Gómez Vega 10.06.2016 в 20:10
source

1 answer

2

The path that is using the get function of jQuery is relative, which results in an incorrect route (404), then a / must be added at the beginning of the same to make an absolute referencing, starting from the root of the current domain:

  $.get("/imp/"+event.target.value, function(response, sociedad) {
      console.log(response);
  });
    
answered by 11.06.2016 / 04:08
source