JAX-RS - @PUT with JQuery Example [Updated: May 30, 2017, Created: Feb 2, 2016] |
|
||
HTML form only supports GET and POST. To use other HTTP Methods from a web browser, we can use JavaScript Ajax call. In this example we are using JQuery API. Here's how an HTML Form along with JQuery can be used to make a PUT (and other HTTP methods) request. $("#the_form_id").submit(function(event){ //disable default form submission event.preventDefault(); var $form = $(this); $.ajax({ type : 'PUT', url : url, contentType: 'application/json', data : form_data//should be converted fo json success : function(data, status, xhr){ //show success message }, error: function(xhr, status, error){ //show error message } }); }); Example ProjectDependencies and Technologies Used:
|
|
||
|
|||
Running the application: Run the
embedded tomcat server:
Use the following link to submit the HTML form:
On sucessful submission you will see the response at the bottom with new resource URI ![]()
Now you can access the new resource at:
Create multiple items from the the HTML form. To see all items use the resource link:
|
|
||
|
|||
|