Advertisement
apuntesdejava

Untitled

Apr 15th, 2013
8,415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.33 KB | None | 0 0
  1.         <script >
  2.  
  3.             var webresource = "<%= getServletContext().getContextPath()%>/webresources";
  4.             var calculadoraRest = webresource + "/calculadora";
  5.             var factorialPath = calculadoraRest + "/factorial";
  6.             function getAuthPairs() {
  7.                 var usr = {
  8.                         user: $("#usuario").val(),
  9.                         password: $("#contrasenia").val()
  10.                     };
  11.                 return usr;
  12.             }
  13.             function init() {
  14.                 $("#factorialBtn").click(function() { //definiendo el evento click del boton #factorialBtn
  15.                     var auth = getAuthPairs();
  16.                     var vBase = $("#f_base").val(); //obteniendo el valor del input #f_base
  17.                     $.ajax(factorialPath,
  18.                             {data: {base: vBase},
  19.                                 username: auth.user,
  20.                                 password: auth.password,
  21.                                 success: function(resp) { //llamando al webservice con el parametro base igual a la variable base
  22.                                     $("#f_resultado").text("Resultado:" + resp); //... muestra el resultado obtenido en resp en el div
  23.                                 }
  24.                             });
  25.                 });
  26.             }
  27.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement