• The site is installed on a Nginx server. With fastcgi_cache. This server displays the cached version regardless of the visitor’s IP. On website installed woocommerce too. All ?AJAX endpoint options is enabled in plugin settings.

    I use these functions:
    geoip_detect2_get_info_from_current_ip()

    Please help with the solution.

    • This topic was modified 1 year, 5 months ago by Artyom.
    • This topic was modified 1 year, 5 months ago by Artyom.
    • This topic was modified 1 year, 5 months ago by Artyom.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Artyom

    (@ryabchuk)

    Maybe there is a function similar to geoip_detect2_get_info_from_current_ip with ajax?

    Thread Starter Artyom

    (@ryabchuk)

    I added this script to js file:

    jQuery(document).ready(function($) {
        $.ajax({
          url: '/wp-admin/admin-ajax.php',
          method: 'GET',
          data: {
            action: 'geoip_detect2_get_info_from_current_ip',
          },
          success: function(response) {
            var country = response.country.names.en;
            var isoCode = response.country.iso_code;
      
            console.log('Country: ' + country);
            console.log('ISO Code: ' + isoCode);
      
            // Make an AJAX request to a separate PHP script
            $.ajax({
              url: '/wp-admin/admin-ajax.php',
              method: 'POST',
              data: {
                url: '/wp-content/themes/bethub/inc/product_layout/side_block.php',
                country: country,
                isoCode: isoCode
              }
            });
          },
          error: function(xhr, status, error) {
            // Handle any errors that occur during the AJAX request
            console.error(error);
          }
        });
      });

    In side_block.php I am calling values:

    $country = $_POST['country'];
    $isoCode = $_POST['isoCode'];
    
    echo 'Values received: ' . $country . ', ' . $isoCode;

    But values are empty. What am I doing wrong?

    • This reply was modified 1 year, 5 months ago by Artyom.
    Plugin Author Benjamin Pick

    (@benjaminpick)

    Did you make sure admin-ajax.php is excluded from the fastcgi cache?

    The jQuery script seems ok (but there is a simplfied JS API if you like: https://github.com/yellowtree/geoip-detect/wiki/API:-AJAX#frontend-js-helper-functions ) . What does the admin-ajax.php call return (see network tab of the DevTools, or call manually?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How does the plugin work with FastCGI cache?’ is closed to new replies.