【问题标题】:Got error while try to use intl-tel-input liberary for country code尝试将 intl-tel-input 库用于国家/地区代码时出错
【发布时间】:2019-09-10 00:35:46
【问题描述】:

我想在全球范围内验证手机号码,所以我搜索了很多,最后得到了 intl-tel-input 库来轻松执行此任务。

我在 GitHub 上使用这个,一切正常。

问题是我没有根据我的项目中的用户 IP 地址获取自动国家代码,但是当我单独使用它时它可以工作。

我正在分享我所做的所有事情。

我正在努力

-MVC ASP

这是我真正想要的屏幕截图。

https://imgur.com/TWjdrVH

这是我得到的截图

https://imgur.com/Yr7MYBx

我遇到了错误

火狐

https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068”中的脚本已加载,即使其 MIME 类型(“text/html”)不是有效的 JavaScript MIME 类型。[了解更多] 注册 源“https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068”的加载失败。注册:1:1

https://imgur.com/Q98ypO7

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

https://imgur.com/whH2rVr

这是我使用的一些代码

查看

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

脚本

<!-- 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>

帮我解决我的问题

我想根据用户 IP 地址获取自动国家代码

【问题讨论】:

  • 这个问题没人解决吗?
  • 一直让我尴尬。没有人在这里解决我的问题
  • 429 响应意味着您受到 IPinfo.io 的限制 - 您达到了他们每天 1000 个请求的免费计划限制。在ipinfo.io/signup 注册访问令牌,您将收到提醒

标签: javascript jquery model-view-controller intl-tel-input


【解决方案1】:

您需要将 url 替换为令牌: 就像:https://ipinfo.io -> https://ipinfo.io?token=$Your_token

您需要在https://ipinfo.io/ 注册以获取您的令牌。

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 2019-02-16
    • 2020-03-15
    • 2019-09-26
    • 2019-09-27
    • 2021-12-02
    • 2023-01-31
    • 2017-06-14
    • 2018-01-08
    相关资源
    最近更新 更多