Reputation: 25
I need to update a form based on some entries that are taken from the user (present in the same form). This allows me to have a single add update page.
2 parameters accepted from the user need to be sent to a struts 2 action. A DB query executed inside the action returns a data set. This data set needs to be sent back to the UI and the UI needs to be updated.
Please help.
Upvotes: 0
Views: 698
Reputation: 160191
Use jQuery's .post() method. The results can be JSON or HTML and handled appropriately.
$.post({
theUrl,
{ field1: "value", field2: "value" },
function(data) { $("#resultsDiv").html(data)
});
If you need more control, you can use the .ajax function.
There are a variety of ways to get an S2 URL into the arguments, including just having the JavaScript in the JSP page and using the tag, having the $.post
call itself in an external JS and calling in from the JSP page passing the URL in, processing your JS files with the JSP processor, and so on.
There are also at least two jQuery plugins that can wrap this up into a tag, but IMO it's easier and cleaner to just do it using "raw" jQuery.
Upvotes: 2