How to send variables through ajax with laravel 5?

0

Hi, I am something new in all this of laravel and ajax, and as a practice I would like to know how to use ajax in laravel ....

Finally, I have the following code:

index.blade.php

   <input type="text" name="textvalue" id="texto">
    <button type="button" id="confirm">confirmar</button>

     <script type="text/javascript">

      $('#confirm').click(function(){
          alert("boton funciona");
             var input=$('#texto').val();

            $.ajax({
            url: 'archivos/create2.blade.php',
            method: 'post',
            data: {'texto': input},
            success:function(data){
                alert('los datos fueron registrados correctamente');
                }, error:function(jqXHR, textStatus, errorThrown){
                    console.log('error::'+errorThrown);
                     console.log('error::'+textStatus);
                      console.log('error::'+jqXHR);
                   }

            });                  
        });
   </script>

Routes.php

   Route::resource('/archivos', 'ArchivoController');
   Route::post('archivos/create2', 'ArchivoController@show');

FileController.php

class ArchivoController extends Controller
{
 public function index()
  {
    //$title = "Modulo de Archivos";
   //EN ESTE sector esto que dice archivos. es de mi carpeta en donde esta el index
    return view('archivos.index', compact('archivos', 'title'));
  }

public function show(){
$data=$this->input->post();
return view('archivos.create2');
  }
    public function store(Request $request)
  {       
  }

}

create2.blade.php

  @extends('templade')
  @section('content')
   <?php
     $entra=$_POST['texto'];
      echo "tabla texto : $entra ";

   ?>
  @endsection
    
asked by Lun 22.11.2017 в 16:07
source

0 answers