java - Use web service in background of HTML -


i have web service , html page , want calculate 2 values , show on third text field code shows me on next page. 1 me fyp.

my index.html

<!doctype html>  <html> <head>     <title>to supply title</title>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head>  <body>  <h1>jax-rs</h1>  <form action="http://localhost:8080/connectingtonode/webapi/myresource?id"                                   method="post" target="_self">     <p>         number1 : <input type="text" name="number1" />     </p>     <p>         number2 : <input type="text" name="number2" />     </p>     <p>         number3 : <input type="text" name="number3" />     </p>       <input type="submit" value="add" />             <p>         total : <input type="text" name="number3" />     </p> </form> </body> </html> 

my web service

@path("myresource") public class myresource{ hashmap<string, string> map= new hashmap<string, string>();  @post @produces(mediatype.text_plain) public response addnumber(         @formparam("number1") int number1,         @formparam("number2") int number2         ) {     int total=number1+number2;     return response.status(200).entity("total : "  +  total).build();          } } 

you want perform ajax call instead of submitting form. build javascript function e.g. using jquery:

$.post("<your servlet here>", $("#y<ourformidhere>").serialize(),callback); 

where callback function this:

function(data){ console.log("data",data); // want response data } 

off course have bind $.post function form button.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -