Grails onSuccess vs onComplete Remote Access Feature

I have the following Grails code:

${remoteFunction(controller: 'myController', 
                     action: 'myMethod',
                     params: 'params',
                  onSuccess: 'mySuccessMethod(data);',
                 onComplete: 'myCompleteMethod();',
                     update: 'divName')};

I would expect:

  • mySuccessMethod()and myCompleteMethod()for each call are called once when the Ajax call ends

I get

  • mySuccessMethod() called immediately
  • When the Ajax call (eventually) ends
    • mySuccessMethod()called the second time
    • myCompleteMethod() called (once).

When looking for this problem, the Ajax recommendation was to use onsuccess, but the implementation (i.e. when it is called) seems different in Grails.

Can someone explain this.

  • Why mySuccessMethod()is it called twice?
  • Does this mean that we should use onComplete, not onsuccessat least in Grails?

(: ​​ .)

HTML- remoteFunction() ( CR ):

jQuery.ajax({type:'POST',data:paramString,
                 url:'/<appname>/myController/myMethod',
                 success:function(data,textStatus){
                     jQuery('#divName').html(data);
                     mySuccessMethod(data);;
                 },
                 error:function(XMLHttpRequest,textStatus,errorThrown){
                 },
                 complete:function(XMLHttpRequest,textStatus){
                     myCompleteMethod();
                 }
             });;

mySuccessMethod :

  • :

    <div class="loading-content"/>
    
  • :

    <The actual expected response>
    

.

+4
1

onComplete ajax, . onSuccess , . , onComplete onSuccess

: - jQuery 1.5 - ajax:

  • success() done()
  • error() fail()
  • complete() always()

Grails 3 jQuery.ajax , .

+4

Source: https://habr.com/ru/post/1529058/


All Articles