Pass and receive data to Servlet in the same AJAX Function

Asked

Viewed 387 times

0

Do you have any way to send parameter to Servlet and receive a json in the same AJAX Function? Example of what I need:

 function UpdateGrafico(){

          $(function () {

                //---------------------
       //aqui preciso enviar uma data para o servlet realizar um select        
      $.ajax({  
     data: "",  
     dataType: 'json',  
     url: './GetValores', 
     type: 'POST', 
     success: function(data){  

           //recebe os dados json e atualiza pagina 
        });
    }

I need this way because on the JSP page there is a button and when I click on it, a date will be taken that the user has selected, and used this date for a select on Servlet, which will return the data to update a chart on the JSP page.

1 answer

0


I found the answer, follow below:

 function UpdateGrafico(){

          $(function () {

                //---------------------
       //aqui preciso enviar uma data para o servlet realizar um select        
      $.ajax({  
     data: varival: "valor1", //aqui passa o valor para o servlet 
     dataType: 'json',  
     url: './GetValores', //nome do servlet
     type: 'POST', 
     success: function(data){  

           //recebe os dados json e atualiza pagina 
        });
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.