cone send data to a web service to receive data

0

Hello, I have two text boxes, their id are color and the other one is tamaño , they receive input data from a page but I do not know how to send my fields to the web service so that I can return my data. the url is where my web service is

$.ajax({
        url: '../mesas.php',
        type: 'POST',
        dataType: 'json',
        data: $(this).serialize(),
        beforeSend: function () {
            $("#color").html();
             $("#tamaño").html();
        }
    })
    
asked by JV93 19.10.2018 в 17:08
source

1 answer

0

Try using the following code. I was explaining in the comments. Anyway, you let me know if something is not understood. Greetings!

function enviar()
  $.ajax({

      //Obtengo los valores de mis campos de texto /input
      var color =$("#color").val();
      var tamaño =$("#tamaño").val();
      
      // En data puedes utilizar un objeto JSON, un array o un query string
      data: {"color" : +'"'+color+'"'+, "tamaño" :'"'+tamaño+'"'},
      //Cambiar a type: GET si necesario
      type: "POST",
      // Formato de datos que se espera en la respuesta
      dataType: "json",
      // URL a la que se enviará la solicitud Ajax
      url: "script.php",
  })
   .done(function( data, textStatus, jqXHR ) {
       if ( console && console.log ) {
           console.log( "La solicitud se ha completado correctamente." );
       }
   })
   .fail(function( jqXHR, textStatus, errorThrown ) {
       if ( console && console.log ) {
           console.log( "La solicitud a fallado: " +  textStatus);
       }
  });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="color" placeholder="Color"/>
<input type="text" id="tamaño" placeholder="Tamaño"/>
<button onclick="enviar();">Enviar</button>
    
answered by 19.10.2018 в 17:26