jQuery with ZetaBoards: Utilizing force_ads

This documentation applies to ZetaBoards only.

This documentation will show you how to prevent your scripts from taking away Ad Removal credits. When you make an AJAX request on ZetaBoards, such as a GET or a POST request, an ad removal credit is taken away from the user's board when the requested page is loaded in the background.

Forum owners who have purchased ad removal credits and have installed scripts that use AJAX requests may see their credits quickly disappear for this reason. However, this can be circumvented by including the force_ads parameter with AJAX requests in your scripts.

This documentation assumes that you have an understanding of JQuery with ZetaBoards: The Basics.

Passing the force_ads parameter (single variable)

When sending your AJAX request, the force_ads variable must be properly passed via the URL for ad removal credits to remain unaffected.

When to use ?force_ads

  1. Use ?force_ads when it is the only variable in the URL query
  2. Use ?force_ads& when it is the first of multiple variables in the URL query

When to use &force_ads

  1. Use &force_ads when it is not the first of multiple variables and is the last variable in the URL query
  2. Use &force_ads& when it is not the first of multiple variables and is not the last variable in the URL query

Example usage

In the example below, an AJAX request is preformed via GET to the user's profile if the user is logged in. The name of the logged in user found on the requested page is then shown in an alert. Because of the presence of the ?force_ads parameter, an ad removal credit is not used.

Tip ZetaBoards embeds variables for you by default. The variables inside of the $.zb.stat array can save you time. Additionally, other useful variables include $.zb.admin, $.zb.moderator, and $.zb.logged_in.
<script type="text/javascript">
    $(function() {
        if ($.zb.logged_in) {
            $.get($.zb.stat.url + 'profile/' + $.zb.stat.mid + '/?force_ads', function(d) {
                alert($('#top_info strong a', d).text());
            });
        }
    });
</script>

Passing the force_ads parameter (multiple variables)

Similarly, the codes below preforms an AJAX request via GET to the topic creation page of a hypothetical forum with an ID of 10000. However, unlike the script above, the page we are requesting already has variables being passed in the URL. With that being said, we have three options.

We can insert &force_ads at the end of the query string.

<script type="text/javascript">
    $(function() {
        if ($.zb.logged_in) {
            $.get($.zb.stat.url + 'post/?type=1&mode=1&f=10000&force_ads', function(d) {
                alert($('#top_info strong a', d).text());
            });
        }
    });
</script>

We can insert ?force_ads followed by an & at the beginning of the query string.

<script type="text/javascript">
    $(function() {
        if ($.zb.logged_in) {
            $.get($.zb.stat.url + 'post/?force_ads&type=1&mode=1&f=10000', function(d) {
                alert($('#top_info strong a', d).text());
            });
        }
    });
</script>

We can also insert &force_ads followed by an & in the middle of the query string.

<script type="text/javascript">
    $(function() {
        if ($.zb.logged_in) {
            $.get($.zb.stat.url + 'post/?type=1&mode=1&force_ads&f=10000', function(d) {
                alert($('#top_info strong a', d).text());
            });
        }
    });
</script>

What about $.post()?

Passing the force_ads parameter applies to both $.get() and $.post() requests.

If force_ads is passed improperly or is not included in the AJAX request, an ad removal credit will be used for both types of requests.



codes/force_ads.txt ยท Last modified: 2016/01/30 11:22 by Ben Babcock