简体   繁体   English

intl-tel-input getExtension 返回“null”

[英]intl-tel-input getExtension returning “null”

I have been trying to get the Extension of the mobile number entered.我一直在尝试输入手机号码的扩展名。 Every other variable is working fine.所有其他变量都工作正常。 The extension variable is returning Null.扩展变量返回 Null。 It seems that it is passing a null value to the POST.似乎它正在向 POST 传递一个空值。

<input type="tel" id="mobile" placeholder="Mobile Number" maxlength="10" >

    <script>
        //Initialize the plugin
            $("#mobile").intlTelInput({
                initialCountry: "auto",
                nationalMode: "true",
                utilsScript:'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/8.5.0/js/utils.js',
                geoIpLookup: function(callback) {
                $.get("https://ipinfo.io", function() {}, "jsonp").always(function(resp) {
                    var countryCode = (resp && resp.country) ? resp.country : "";
                    callback(countryCode);
                });
            }
            });    

        //Ajax Registration
            $("#register").click(function(){

            var email = $("#email").val();
            var password = $("#password").val();
            var confirmpassword = $("#confirmpassword").val();
            var fname = $("#fname").val();
            var lname = $("#lname").val();
            var mobile = $("#mobile").val();
            var role = $("#role").val();
            var extension = $("#mobile").intlTelInput("getExtension");

            var data = "email=" + email + "&password=" + password + "&fname=" + fname + "&lname=" + lname + "&mobile=" + mobile + "&role=" + role + "&confirmpassword=" + confirmpassword + "&extension=" + extension;  

            $.ajax({
                type:"POST",
                url:"includes/register.php?",
                data:data,
                success:function(data)
                {
                    $("#register_output").html(data);
                }
            });
    </script>

I believe the getExtension method is now deprecated.我相信 getExtension 方法现在已被弃用。 If you want the country code on its own, you can get it at iti.s.dialCode .如果您需要自己的国家/地区代码,可以在iti.s.dialCode Something like this:像这样的东西:

<label>Phone</label><input class="textbox" type="tel" name="phone" id="phone" value=""><br>

<script>
    var input = document.querySelector('#phone');

    var iti = intlTelInput(input, {
        utilsScript: 'assets/tel-input/js/utils.js',
        initialCountry: 'au'
    });

    $('#send').on('click', function(param) {
        var fullPhone = "+" + iti.s.dialCode + iti.getNumber();
        console.log(fullPhone)
    });
</script>

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

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