How to pass jquery content from one variable to another to be sent by ajax to a php document?

0

I have the following code proceso.js

(function ($) {
  $.fn.Carpeta = function (options) {
    var defaults = {
        codigoI: false,
        };

    this.each(function () {
        var crear = $(this);

         if (options.input) {
          $(createInput).find('.confirm').click(function () {                       
                if ($(createInput).find('input').val() === '')
                 return;
       //Aqui es donde tengo la variable que captura el dato y lo imprime por pantalla
            var input= $(createInput).find('input').val();
     });

       };
     })(jQuery);

index.php

    @extends('templade')
    @section('content')
      <p align="right"><?php echo date('l j \of F Y H:i:s');?></p>

        <script src="js/proceso.js"></script>

         <div class="col-md-11">
            <div class="carpeta" id="carp">
              <ul>
                  <li> </li>            
              </ul>                    
            </div>     
         </div>     

   <script>
(function ($) {
    function init() {
        $('.carpeta').Carpeta({
             codigoI: true,              
        });
    }
    window.onload = init();

 })(jQuery)

</script>

 @endsection

Now my question is how can I send from jquery the contents of that variable 'input' to my php document and then store it in the database?

    
asked by Lun 14.11.2017 в 20:09
source

1 answer

1

when you press your button assign submit and add the (id) to the form (Add form) with serialize saves all the values of the imput and save it in a variable for example frm, then you have to give the url of your file php and in your php file you receive them with $ _post ['name'] between commas the name of the input (name)

<button type="submit" name="enviar" id="agregar" class="btn btn-primary">Agregar</button>

$( "#formularioAgregar" ).submit(function( event ) {
      event.preventDefault();
      var frm= $(this).serialize();
       $.ajax({
       type:"POST",
       url: 'index.php?accion=guardar',
       data: frm,
       success: function(data){
        $('#formularioAgregar')[0].reset();
        window.location.replace("index.php?accion=index");
        $('#resp').html('Se Agrego Correctamente El Status').show(200).delay(2500).hide(200);
       }
        })
    });
    
answered by 14.11.2017 в 20:23