地理位置js出错(site.init未定义)

时间:2017-11-06 19:18:43

标签: javascript ajax geolocation ip frontend

我目前有问题, 我有一个客户希望他在阿根廷的网站只在阿根廷看到,从其他国家进入的用户被重定向到法国的官方网站,如果你在阿根廷境内进行API查询,地理定位脚本是没有执行应该注意,唯一的方法,我使用的api是ip api,我必须在js中创建它。因为我们使用的系统不能让我们访问服务器。另外还必须保存一个cookie。所以我做了以下几点。

var site = {
    init: function() {

        this.setDisplayClass();
        this.global();
        this.search();
        this.newsletter();
        menu.init();
        minicart.amount(".cart-link .qty-items");
        minicart.create();
        minicart.hover();
        if ($('body').hasClass('home')) {
            banner.background('.main-banner-section .box-banner');
            banner.slide('.run-slick');
            shelf.slide('.featured-products-slider .shelf ul');
        }
        if ($('body').hasClass('grid-products')) {
            grid.init();
        }
        if ($('body').hasClass('producto')) {
            product.init();
            shelf.slide('#related-products .shelf ul');
        }
    },
}

AND

var geo ={
    init: function(){
        var isAr = localStorage.getItem("country");
        if((isAr == null) || (isAr == undefined)){
            $.ajax({
                url: 'http://ip-api.com/json/?callback=?',
                async: false,
                dataType: 'jsonp',
                success: function (response) {
                    var country = response.countryCode;
                    if(country !== "AR"){
                        window.location.replace("https://www.google.com.ar");
                    }else{
                        localStorage.setItem('country', country);
                        if($(".loading-hidden").length > 0){
                            $(".loading-hidden").each(function(){
                                if ($(this).attr('style') == 'visibility: hidden;') {
                                    console.log(1);
                                    site.init();
                                    $(this).removeAttr('style');
                                    if ($("#loading").length > 0) {
                                        $("#loading").remove();
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }else{
            if ($(".loading-hidden").attr('style') == 'visibility: hidden;') {
                            site.init();
                            $('.loading-hidden').removeAttr('style');
                            if ($("#loading").length > 0) {
                                $("#loading").remove();
                            }
                        }
        }

    }
}

AND

$(document).on('ready', function() {
});
site.init();

    $(window).bind("load", function() {

});

我得到的错误是site.init未定义。

0 个答案:

没有答案