Fill modal with data through ajax and web services

0

I have a project where I must fill a modal window from the database using Ajax, I will explain the project, I have the web services rest in C # and I am consuming it from Java 2EE with servlet and a class called Web Services, but at the moment of doing the Ajax in the Java project, tells me that the url of the method does not find it, this method is SearchPerId (); then, when pressing the button modify the one that appears in the photo with a box and an arrow, the button has the id of the element in the value=""; , then when I press it I should look for ID in the database, in a photo I will leave the error that appears.

$('.keyModal').click(function (){
       console.log("Modal esta abierto");
      $('#myModal').modal('show');

        var idFormulario = $(this).attrib('id'); //Tenemos el id del formulario

            $.ajax({
                dataType: 'Json',
                type: 'POST',
                url: 'BuscarMedicamentoPorId/',
                data: {id = idFormulario},
                success: function (r)
                {
                    console.log("Ejecutó metodo");
                    //Seteamos los input
                    $('#txtDescripcionEditar').val(r['DESCRIPCION']);
                    $('#txtContenidoEditar').val(r['CONTENIDO']);
                    $('#txtGramajeEditar').val(r['GRAMAJE']);

                    //Seteamos los valores <select>
                    $("select#seleccioneTipoEditar").val(r['MED_IDTIPOMEDICAMENTO']).attr('selected', true);
                    $("select#seleccioneViaEditar").val(r['VIAADMIN_IDVIAADMIN']).attr('selected', true);
                }
            });
        });

    
asked by Danilo Belmar Dinen 22.05.2017 в 05:16
source

1 answer

1

Your problem is that you are not extracting id doing this:

var idFormulario = $(this);

you are getting an element of the DOM , which is the button that you have clicked, if you want to get the id of the element change that line for this:

var idFormulario = $(this).attr('id');//buscas el atributo que contiene el identificador

and to send it from the ajax in the attribute data you have this change:

$.ajax({
  ...
  data: {id = idFormulario}
  ...
});
    
answered by 22.05.2017 в 18:04