I have a Spring Mvc application and i want when the user clicks on the submit button and is returned to the view that a jquery dialog be displayed like ‘Transaction was successful‘ or an error message if any in a dialog.
Presently when the form reaches the controller once processing is done if the transaction is successful or any errors i set model.addAttribute(‘ServerResponse’, ‘Transaction Was successful’) or model.addAttribute(‘ServerResponse’,e).
I would like to return ‘ServerResponse‘ into the dialog however i dont know what is the best event to attach the jquery to. I don’t want to create a web service since i am already using a post to the server and in the event javascript is turned off.
Can someone tell me whats the best way to show the dialog with the ServerResponse once the ServerResponse element has a value. Initially when the form is loaded ServerResponse should be empty.
Hope i was clear enough on what i am trying to achieve here.
Edited
This is what i am doing but the function is not executing when i return form the server its actually displaying at the point where the div was created.
<div id="dialog" title="Server Response">
<p>
<span class="ui-icon ui-icon-info" style="float: left; margin: 0 7px 50px 0;"></span>
${results}
</p>
</div>
$(function() {
var serverResponse = $('#serverResponse').val().length;
alert(serverResponse);
if(serverResponse != 0){
alert(serverResponse);
$("#dialog").dialog();
}
});
Output the message from the model into a div using whatever template language you’re using in your view layer. Something like:
Style accordingly and then in jquery (with jquery UI) on that page do:
And then do whatever styling you want. The plain div will display if there’s no javascript or will be pulled in to the dialog if there is. You could use a
noscriptand duplicated content to eliminate the momentary flash of content before its pulled into the dialog.