简体   繁体   English

尝试将国际电话输入库用于国家代码时出错

[英]Got error while try to use intl-tel-input liberary for country code

I want to validate mobile number worldwide,so i have search a lot and finally get intl-tel-input library to perform this task easily.我想在全球范围内验证手机号码,所以我进行了很多搜索,最后得到了 intl-tel-input 库来轻松执行此任务。

im using this from GitHub, all thing work fine.我从 GitHub 使用它,一切正常。

Problem is that im not getting auto Country Code based on user ip address in my project but when i use it individually it works.问题是我没有在我的项目中根据用户 ip 地址获取自动国家代码,但是当我单独使用它时它有效。

im sharing all thing that i have done.我分享我所做的一切。

im working on我正在尝试

-MVC Asp -MVC ASP

Here is the screenshot that i actually want.这是我真正想要的屏幕截图。

https://imgur.com/TWjdrVH https://imgur.com/TWjdrVH

Here is the screenshot that i got yet这是我得到的截图

https://imgur.com/Yr7MYBx https://imgur.com/Yr7MYBx

Error i got我得到的错误

Firefox火狐

The script from “ https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068 ” was loaded even though its MIME type (“text/html”) is not a valid JavaScript MIME type.[Learn More] Register Loading failed for the with source “ https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068 ”.来自“ https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068 ”的脚本被加载,即使它的 MIME 类型(“text/html”)不是有效的 JavaScript MIME 类型。[了解更多] 注册加载失败来源“ https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068 ”。 Register:1:1注册:1:1

https://imgur.com/Q98ypO7 https://imgur.com/Q98ypO7

Chrome铬合金

GET https://ipinfo.io/?callback=jQuery112403105878441128118_1555701843619&_=1555701843620 net::ERR_ABORTED 429获取https://ipinfo.io/?callback=jQuery112403105878441128118_1555701843619&_=1555701843620 net::ERR_ABORTED 429

https://imgur.com/whH2rVr https://imgur.com/whH2rVr

Here is some code that i used这是我使用的一些代码

View看法

@Html.EditorFor(model => model.user_mobile, new { htmlAttributes = new { @class = "form-control", id = "mobile" } })

Scripts脚本

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="~/js/bootstrap.min.js"></script>

<!-- Multi select -->
<script src="~/js/multi_select.js"></script>

<!-- Select 2-->
<script src="~/js/select2/select2.full.min.js"></script>



<!-- Custom JS File -->
<script src="~/js/custom.js"></script>

<script src="~/Scripts/validation/phone/intlTelInput.js"></script>
<script type="text/javascript">

    var input = document.querySelector("#mobile");
    window.intlTelInput(input, {
        initialCountry: "auto",
        geoIpLookup: function (callback) {
            $.get('https://ipinfo.io', function () { }, "jsonp").always(function (resp) {
                var countryCode = (resp && resp.country) ? resp.country : "";
                callback(countryCode);
            });
        },
        //utilsScript: "build/js/utils.js" // just for formatting/placeholders etc
    });

    $(function () {
        $('.multiselect-ui').multiselect({
            includeSelectAllOption: true
        });
    });

    // Select 2 searchable
    $(function () {
        //Initialize Select2 Elements
        $('.select2').select2()
    });





</script>

Help me out to solve my problem帮我解决我的问题

i want to get auto country code based on user ip address我想根据用户 ip 地址获取自动国家代码

You need to replace url with token: be like: https://ipinfo.io -> https://ipinfo.io?token= $Your_token您需要用令牌替换 url:就像: https ://ipinfo.io -> https://ipinfo.io?token= $Your_token

You need to register at https://ipinfo.io/ at get your token.您需要在https://ipinfo.io/上注册以获取您的令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM