1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Closed Suggestions' started by tenants, Jul 8, 2014.

  1. tenants

    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: Jul 8, 2014
    Geca likes this.
  2. Mike

    Mike XenForo Developer Staff Member

    You can already do this with "global: false" passed as an option.
     
  3. tenants

    tenants Well-Known Member

    ah, thank you
     
  4. tenants

    tenants Well-Known Member

    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: Jul 8, 2014

Share This Page