未捕获的ReferenceError:未定义RegisterUserAcc

时间:2016-07-11 03:19:43

标签: javascript html5

我在网上搜索过这个错误并尝试了我读过的所有建议,但似乎我的情况有所不同。

我正在使用intel xdk开发一个跨平台应用程序,应用程序框架3。

我在按钮onclick事件中得到“Uncaught ReferenceError:RegisterUserAcc未定义”。

html5代码的概要:

<div class="col uib_col_2 col-0_4-12" data-uib="layout/col" data-ver="0">
                            <div class="widget-container content-area vertical-col">
                                <div class="table-thing with-label widget uib_w_40 d-margins" data-uib="app_framework/input" data-ver="2">
                                    <input class="wide-control" type="text" id="acode" value="27">
                                </div>
                                <span class="uib_shim"></span>
                            </div>
                        </div>
                        <div class="col uib_col_3 col-0_8-12" data-uib="layout/col" data-ver="0">
                            <div class="widget-container content-area vertical-col">
                                <div class="table-thing with-label widget uib_w_13 d-margins" data-uib="app_framework/input" data-ver="2">
                                    <input class="wide-control" placeholder="Cell Number" type="text" id="regcell">
                                </div><span class="uib_shim"></span>
                            </div>
                        </div>

                        <span class="uib_shim"></span>
                    </div>

                    <div class="table-thing with-label widget uib_w_14 d-margins" data-uib="app_framework/input" data-ver="2">

                        <input class="wide-control" placeholder="Email (e.g. someone@yrdomain.com)&quot;" type="text" id="regemail">
                    </div>
                    <div class="table-thing with-label widget uib_w_15 d-margins" data-uib="app_framework/input" data-ver="2">

                        <input class="wide-control" placeholder="Username" type="text" id="regusername">
                    </div>
                    <div class="table-thing with-label widget uib_w_16 d-margins" data-uib="app_framework/input" data-ver="2">

                        <input class="wide-control" placeholder="Password" type="password" id="regpassword">
                    </div>
                    <div class="table-thing with-label widget uib_w_17 d-margins" data-uib="app_framework/input" data-ver="2">

                        <input class="wide-control" placeholder="Confirm Password" type="password" id="regconfirm">
                    </div><a class="button widget uib_w_18 d-margins" data-uib="app_framework/button" data-ver="2" onclick="RegisterUserAcc()" id="uib_w_18">Create Account</a>
                </div>

标头中的JavaScript具有以下功能:

function validateEmail(email) {
        var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
        };
        function LookUpUsers(usernames){
                        $.ajax({
                            type: "GET",
                            data: Username:usernames,
                            url: "http://localhost:55288/ServiceAPIServer.svc/LookupUser",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            processdata: true, 
                            success: function(nuser) {
                            if(nuser=="" || nuser==null){return true;}else{return false;}
                            },
             });
        };

        function RegisterUserAcc(){


           var reguser=document.getElementById("regusername").value;
           alert("lookup user")
           var UsernameAvailable =LookUpUsers(reguser);
            alert("lookup user succeded, now analising data")
            if (UsernameAvailable==false){alert("Username not available, try another one."); return false;}
           var regpass=document.getElementById("regpassword").value; 
           var regconfirms=document.getElementById("regconfirm").value;
           var regemails=document.getElementById("regemail").value;
           var regcel=document.getElementById("regcell").value;
            var reglat
            var reglon
            var reggetLocation = function()
            {
                var regsuc = function(regp){
                alert("geolocation success");
                if (regp.coords.latitude != undefined)
                {
                reglat = regp.coords.latitude;
                reglon = regp.coords.longitude;
                }

                };
                var regfail = function(){
                alert("geolocation failed");
                reggetLocation();
                };

                intel.xdk.geolocation.getCurrentPosition(regsuc,regfail);
            }
           var regdc= new Date();
            var regimei=intel.xdk.device.uuid;
            var regip
            var regll=regdc;
            var reglocd=regdc;
             $.ajax({
                            type: "GET",
                            url: "http://localhost:55288/ServiceAPIServer.svc/GetRequestIp",
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            processdata: true, 
                            success: function(regmyip) {
                            regip=regmyip;
                            },
             });


            if (reguser==null || reguser=="",regpass==null || regpass=="",regconfirms==null || regconfirms=="",regemails==null || regemails=="",regcel==null || regcel==""){
                alert("All fields are compulsory");
            return false;} else {
                    if(regconfirms!=regpass){alert("Passwords do no match");
                                      return false;}
                }
            if (validateEmail(regemails)){}else{alert("Invalid e-mail address"); return false;}
            if (regpass.length<6){alert("Password must be 6 characters or more"); return false;}

            $.ajax({
                            type: "POST",
                            url: "http://localhost:55288/ServiceAPIServer.svc/CreateUser",
                            data: JSON.stringify({Cell:regcel,DateCreated:regdc,Email:regemails,IMEI1:regimei,Ip1:regip,LastLogin:regll,Lat1:reglat,Loc1Date:reglocd,Lon1:reglon,Password:regpass,Username:reguser}),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            processdata: true, 
                            success: function() {
                             intel.xdk.cache.setCookie("UserId",reguser,366)
                             activate_page("#Ad");
                            },

                        });
        }

2 个答案:

答案 0 :(得分:0)

第8行有一个拼写错误:数据:用户名:用户名,

它应该是数据:{用户名:用户名},或类似的东西

答案 1 :(得分:0)

脚本中的一个括号未关闭,关闭它修复了问题。感谢您的投入,他们帮我修复了我的代码中的其他错误。