0

How can you use AJAX to post jsp pages to a SpringMVC controller. I would like to integrate AJAX into a SpringMVC application. Also would it be better to use html list box and set an event on it so any changes to the data in the database can be persisted when the user clicks on the item or can this be accomplished very easily with JQuery controls.

I am new to using AJAX so i would like if someone can point me in the direction of a good example on posting a form to a controller for processing using AJAX and also the use of JQuery controls that bind to a database.

1 Answer 1

1

Following is the jquery way of making an AJAX call.

$(".delete").click(function(){
                $.ajax({
                    url: '<c:url value="/relyingparty/delete"/>' + '?id=' + $(this).attr("refId") ;,
                    type: 'POST',
                    success: function(result) {

                    }
                });
});

(This is just a sample and not a complete working one)

For the url that is mentioned above you should have a Spring MVC controller with a method annotated with @RequestMapping

@RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    public String deleteRelyingParty(@RequestParam(required = true) Integer id){
}
Sign up to request clarification or add additional context in comments.

2 Comments

How about the jsp how would i code that will i have to register an event on a button? what happens to the <form> tag, do i remove the action and method properties?
the .delete i used here is the css class for the element. If you want to do an ajax implementation for a button you can associate the button's click event. For example your button's id is "button1" then you can do like $("#button1").click(function(){$.ajax(..)}) similar to the above code. You dont need to remove the form tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.