Implemented XenForo.ajax parameter to turn off #AjaxProgress overlay icon loader

tenants

Well-known member
For some plugins, you might want to do things silently with JavaScript (for things that don't entirely matter when they are complete, but you don't want to bother the users), but there is no way to do this and still use the XenForo ViewPublic and only send back the json response

Code:
XenForo.ajax("someurl'", {someparam:"{$someparam}}, function(ajaxData, textStatus)
{
    if(textStatus == "success"){alert.("success");}
})
Using XenForo.ajax will always initiate the XenForo #AjaxProgress loading icon

Code:
<script>
var sendData = {
_xfResponseType: "json",
_xfToken: "{$visitor.csrf_token_page}"
};

$.ajax({
type: "POST",
url: "{xen:link myplugin/here}",
data: sendData,
dataType: "json",
headers: {'X-Ajax-Referer': window.location.href},
timeout: 30000, // 30s
success: function (ajaxData, textStatus) {},
});
</script>
Using the _xfResponseType: "json" is required to be able to use the ViewPublic and only send back the json response, but as soon as we use _xfResponseType: "json", we see the XenForo #AjaxProgress icon

All we would need is an extra param in XenForo ajax that would be set to true by default, but we could set to false:

XenForo.ajax(string url, array params, boolen displayProgress=true)
 
Last edited:
Upvote 1
This suggestion has been implemented. Votes are no longer accepted.
So, this works
Code:
<script>
          var sendData = {
              _xfResponseType: "json",
              _xfToken: "{$visitor.csrf_token_page}"
          };

          $.ajax({
              type: "POST",
              url: "{xen:link myplugin/bla}",
              data: sendData,
              global: false,
              dataType: "json",
              headers: {'X-Ajax-Referer': window.location.href},
              timeout: 30000, // 30s   
          });
    });
</script>
That's fine for me (no progress overlay and still a json response from the viewPublic)

And to do the same with XenForo.ajax :
Code:
XenForo.ajax(
              {xen:link myplugin/bla},
              {someParam: someParam},
              function(ajaxData, textStatus){},
              {global: false}
);

Also works, thanks :)
 
Last edited:
Back
Top Bottom