![](/img/trans.png)
[英]Get input value for country code with jquery [auto country by IP/intl-tel-input jquery library]
[英]Got error while try to use intl-tel-input liberary for country code
我想在全球范圍內驗證手機號碼,所以我進行了很多搜索,最后得到了 intl-tel-input 庫來輕松執行此任務。
我從 GitHub 使用它,一切正常。
我分享我所做的一切。
我正在嘗試
-MVC ASP
這是我真正想要的屏幕截圖。
這是我得到的截圖
我得到的錯誤
來自“ https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068 ”的腳本被加載,即使它的 MIME 類型(“text/html”)不是有效的 JavaScript MIME 類型。[了解更多] 注冊加載失敗來源“ https://ipinfo.io/?callback=jQuery112405092049163202047_1555700688067&_=1555700688068 ”。 注冊:1:1
獲取https://ipinfo.io/?callback=jQuery112403105878441128118_1555701843619&_=1555701843620 net::ERR_ABORTED 429
這是我使用的一些代碼
@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 地址獲取自動國家代碼
您需要用令牌替換 url:就像: https ://ipinfo.io -> https://ipinfo.io?token= $Your_token
您需要在https://ipinfo.io/上注冊以獲取您的令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.