Need to use the model attribute after completion of ajax call in jquery dialog

Soheb

In JS file, i am invoking an ajax call on click of button which is in jquery dialog. Spring MVC Controller method is invoked which does db entry & creates an object as per it and add in model. The same object properties i use as arguments for spring:message in dialog, but not able to get the object from model. Is there any other way? Note: I need to use message from properties file only.

JSP file

 <html>
    ..
    <form:form>
    form elements
    <div id="dialog-form" class="dialogbox">
    <spring:message  code="product.createsuccess" arguments="${message.prodCode}, ${message.customerName}, ${message.warehouseName}, ${message.status}"></spring:message>  
   textbox for entering id & done button code segment
    </div>
    </form:form>
    </html>

Properties file

product.createsuccess = Product {0} created successfully for Customer {1} at {2} in status {3}.

Controller file

public @ResponseBody
    String addWarehouseProduct(@PathVariable Long warehouseId, ModelMap model, Principal principal) {
// db operation
model.put("message", createdMessageObjectwithattributes);
return null;
}

segment of Javascript file

..
$( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 330,
        width: 540,
        modal: true
    });

    $('#done').click(function(){
            var warehouseId = null;
            // warehouseid got from textbox code
            if(warehouseId != null) {
                var url = $('#contextPath').val() +"/"+ $('#mdmType').val()+ "/addWarehouseProduct/" + warehouseId + "/*.do";
                $.ajax({
                    type: "POST",
                    url: url,



                    error: function(e) {

                        alert('Error: ' + e);
                    }
                });
            }
            return false;
        });

..
a better oliver

The model is only used when you return a view.

public @ResponseBody String

means that the method returns a simple String, not a view, to the client. Note the @ResponseBody annotation.

return null;

means that you in fact return nothing. The client gets an empty response.

<spring:message  code="product.createsuccess" arguments="${message...

is only evaluated when the page is being rendered. It does not change after the ajax call.

Two easy solutions come to my mind:

  • Create the message on the server, return it and insert it into the dialog via JavaScript.
  • Create a view (JSP) that contains only the dialog, return that and insert the returned dialog into the current page.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

jQuery: Return data after ajax call success

From Dev

jQuery functionality not working after AJAX call

From Dev

Data attribute length check after Ajax call

From Dev

JQuery datepicker not working after ajax call

From Dev

jQuery UI tabs not working after Ajax call

From Dev

Need to call c# method after jquery dialog form is valid

From Dev

after second ajax call jquery not working

From Dev

programatically disable a button on a jquery ui dialog until ajax call complete?

From Dev

AngularJS: How to execute a controller function AFTER completion of AJAX call in a service?

From Dev

jQuery UI datepicker reinitialize after ajax call

From Dev

JQuery: How to callback each loop after completion of ajax call?

From Dev

JSON data disappears after AJAX call with jQuery

From Dev

Rails 4: update model attribute with AJAX call

From Dev

jQuery update li class attribute href after ajax call

From Dev

Adding a delay to JQuery keyup() after Ajax call

From Dev

jQuery function not working after making an ajax call

From Dev

Why page reloads after JQuery ajax call?

From Dev

Data attribute length check after Ajax call

From Dev

Need to call c# method after jquery dialog form is valid

From Dev

jquery dialog add button after ajax call

From Dev

Jquery UI call ajax from dialog and show the response in the content

From Dev

Using jquery UI's dialog() function with ajax call

From Dev

JQUERY - Bubbling after ajax call

From Dev

JQuery: How to callback each loop after completion of ajax call?

From Dev

jQuery update li class attribute href after ajax call

From Dev

How to wait for completion of an animation chain and an ajax call with jQuery?

From Dev

Loop in Jquery after Ajax call

From Dev

Updating data attribute after ajax call

From Dev

Ajax call after jQuery UI Confirmation Dialog

Related Related

  1. 1

    jQuery: Return data after ajax call success

  2. 2

    jQuery functionality not working after AJAX call

  3. 3

    Data attribute length check after Ajax call

  4. 4

    JQuery datepicker not working after ajax call

  5. 5

    jQuery UI tabs not working after Ajax call

  6. 6

    Need to call c# method after jquery dialog form is valid

  7. 7

    after second ajax call jquery not working

  8. 8

    programatically disable a button on a jquery ui dialog until ajax call complete?

  9. 9

    AngularJS: How to execute a controller function AFTER completion of AJAX call in a service?

  10. 10

    jQuery UI datepicker reinitialize after ajax call

  11. 11

    JQuery: How to callback each loop after completion of ajax call?

  12. 12

    JSON data disappears after AJAX call with jQuery

  13. 13

    Rails 4: update model attribute with AJAX call

  14. 14

    jQuery update li class attribute href after ajax call

  15. 15

    Adding a delay to JQuery keyup() after Ajax call

  16. 16

    jQuery function not working after making an ajax call

  17. 17

    Why page reloads after JQuery ajax call?

  18. 18

    Data attribute length check after Ajax call

  19. 19

    Need to call c# method after jquery dialog form is valid

  20. 20

    jquery dialog add button after ajax call

  21. 21

    Jquery UI call ajax from dialog and show the response in the content

  22. 22

    Using jquery UI's dialog() function with ajax call

  23. 23

    JQUERY - Bubbling after ajax call

  24. 24

    JQuery: How to callback each loop after completion of ajax call?

  25. 25

    jQuery update li class attribute href after ajax call

  26. 26

    How to wait for completion of an animation chain and an ajax call with jQuery?

  27. 27

    Loop in Jquery after Ajax call

  28. 28

    Updating data attribute after ajax call

  29. 29

    Ajax call after jQuery UI Confirmation Dialog

HotTag

Archive