Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何调用身体负荷函数_Javascript_Jquery_Json_Ajax - Fatal编程技术网

Javascript 如何调用身体负荷函数

Javascript 如何调用身体负荷函数,javascript,jquery,json,ajax,Javascript,Jquery,Json,Ajax,这里我试图在body load上调用oauth2\u login()函数,它应该登录用户。到目前为止,我正在将数据库中存在的值硬编码到用户名和密码字段中 <!DOCTYPE html> <html> <!-- * Please see the included README.md file for license terms and conditions. --> <head> <title>Blank Cordova Mobi

这里我试图在body load上调用
oauth2\u login()
函数,它应该登录用户。到目前为止,我正在将数据库中存在的值硬编码到用户名和密码字段中

<!DOCTYPE html>
<html>
<!--
* Please see the included README.md file for license terms and conditions.
-->
<head>
    <title>Blank Cordova Mobile App Template</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <!-- see http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-dont-forget-the-viewport-meta-tag -->
    <!-- <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1"> -->
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, minimum-scale=1, maximum-scale=2"> -->
    <!-- <link rel="stylesheet" href="css/app.css">-->
    <style>
        /* following two viewport lines are equivalent to meta viewport statement above, and is needed for Windows */
        /* see http://www.quirksmode.org/blog/archives/2014/05/html5_dev_conf.html and http://dev.w3.org/csswg/css-device-adapt/ */
        @-ms-viewport {
            width: 100vw;
            min-zoom: 100%;
            zoom: 100%;
        }

        @viewport {
            width: 100vw;
            min-zoom: 100% zoom: 100%;
        }

        @-ms-viewport {
            user-zoom: fixed;
            min-zoom: 100%;
        }

        @viewport {
            user-zoom: fixed;
            min-zoom: 100%;
        }
        /*@-ms-viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }   @viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }*/

        .dispInline,
        .dispInlineLabel {
            display: inline-grid;
            border-bottom-width: 0;
        }

        .dispInlineLabel {
            min-width: auto;
        }

        .dispInline {
            min-width: auto;
        }

        .clearFloats {
            clear: both;
        }

        #tck_id {
            padding-bottom: 10px;
        }
    </style>
    <!-- See explanation at the bottom of this file for info regarding placement of JS libraries. -->
    <!-- These library references (below) are just examples to give you the general idea... -->
    <!-- <script src="lib/mc/hammer.js"></script> -->
    <!-- <script src="lib/ft/fastclick.js"></script> -->
    <!-- <script src="lib/jq/jquery.js"></script> -->
    <!--    <link rel="stylesheet" href="css/New.css" type="text/css">-->
    <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body onload="oauth2_login()">
<div data-role="page" id="paper">
    <div data-role="header" data-theme="b" data-position="fixed">
        <a href="#home" data-icon="arrow-l" data-iconpos="notext" data-direction="reverse" onclick="location.href='home.html'">Back</a>
        <h1>Hello</h1>
    </div>
    <div data-role="content">
        <!--       <div class="clearFloats"></div>-->
        <!--  <button onclick="getLocation()">Try It</button>-->
        <p id="demo"></p>
        <div data-role="footer" data-position="fixed" data-theme="b">
            <!-- fixed footer -->
            <div data-role="navbar">
            </div>
        </div>
    </div>
</div>

<script>
    function oauth2_login() {
        var email = "abhigyan.gaurav@99rstreet.com";
        var password = "abhigyan@123";
        var dataString = "User=" + email + "&Pass=" + password + "&login=";
        if ($.trim(email).length > 0 & $.trim(password).length > 0) {
            $.ajax({
                type: "POST",
                url: "http://35.201.138.23:8080/APIPRODUCTION/OperationJSP/operations.jsp",
                data: dataString,
                crossDomain: true,
                cache: false,
                beforeSend: function() {
                    $("#callAjax").html('Connecting…');
                },
                success: function(data) {
                    var Data = $.parseJSON(data);
                    if (Data.success == '1') {
                        localStorage.login = "true";
                        //localStorage.email = email;
                        var theName = $.trim($("#theName").val());
                        var thePassword = $.trim($("#thePassword").val());
                        localStorage.setItem("PMUsername", theName);
                        localStorage.setItem("PMPassword", thePassword);
                        localStorage.setItem("PMResponse", Data.success);
                        alert("Login Successful");
                        window.location.href = "home.html";
                    } else if (Data.success == '0') {
                        // document.getElementById("waiting").innerHTML = " ";
                        alert("Wrong User");
                        $("#callAjax").html('Login');
                    }
                }
            });
        }
        return false;
    });

    function Loading() {
        document.getElementById("waiting").innerHTML = "Loading...";
    }
</script>
<script src="cordova.js"></script>
<!-- for your event code, see README and file comments for details -->
<script src="js/paper.js"></script>
<!-- for your init code, see README and file comments for details -->
<script src="js/init-app.js"></script>
<!-- normalizes device and document ready events, see file for details -->
<script src="xdk/init-dev.js"></script>
<!-- IMPORTANT: Do not include a weinre script tag as part of your release builds! -->
<!-- Place your remote debugging weinre script URL here, if it does not work above. -->
</body>
</html>

空白Cordova移动应用程序模板
/*下面的两条视口线相当于上面的元视口语句,是Windows所必需的*/
/*看http://www.quirksmode.org/blog/archives/2014/05/html5_dev_conf.html 及http://dev.w3.org/csswg/css-device-adapt/ */
@-ms视口{
宽度:100vw;
最小变焦:100%;
变焦:100%;
}
@视区{
宽度:100vw;
最小缩放:100%缩放:100%;
}
@-ms视口{
用户缩放:固定;
最小变焦:100%;
}
@视区{
用户缩放:固定;
最小变焦:100%;
}
/*@-ms视口{用户缩放:缩放;最小缩放:100%;最大缩放:200%;}@viewport{用户缩放:缩放;最小缩放:100%;最大缩放:200%;}*/
.dispinle,
.dispInlineLabel{
显示:内联网格;
边框底宽:0;
}
.dispInlineLabel{
最小宽度:自动;
}
.dispinle{
最小宽度:自动;
}
.clearFloats{
明确:两者皆有;
}
#tck_id{
垫底:10px;
}
你好

函数oauth2_login(){ var email=“abhigyan。gaurav@99rstreet.com"; var密码=”abhigyan@123"; var dataString=“User=“+email+”&Pass=“+password+”&login=”; 如果($.trim(电子邮件).length>0和$.trim(密码).length>0){ $.ajax({ 类型:“POST”, url:“http://35.201.138.23:8080/APIPRODUCTION/OperationJSP/operations.jsp", 数据:dataString, 跨域:是的, cache:false, beforeSend:function(){ $(“#callAjax”).html('Connecting…'); }, 成功:功能(数据){ var Data=$.parseJSON(数据); 如果(Data.success==“1”){ localStorage.login=“true”; //localStorage.email=电子邮件; var theName=$.trim($(“#theName”).val(); var thePassword=$.trim($(“#thePassword”).val(); setItem(“PMUsername”,名称); setItem(“PMPassword”,密码); setItem(“PMResponse”,Data.success); 警报(“登录成功”); window.location.href=“home.html”; }else if(Data.success==“0”){ //document.getElementById(“waiting”).innerHTML=“”; 警报(“错误用户”); $(“#callAjax”).html('Login'); } } }); } 返回false; }); 函数加载(){ document.getElementById(“waiting”).innerHTML=“正在加载…”; }
我需要一些帮助和建议。这有什么问题?以上是我使用的所有代码。 谢谢

方法1: 使用纯javascript(dom事件)

方法1: 使用纯javascript(dom事件)


在side jquery的document ready函数中调用您的函数:

$(document).ready(function() {
  oauth2_login();
});

在side jquery的document ready函数中调用您的函数:

$(document).ready(function() {
  oauth2_login();
});

实际上,您会遇到两个控制台错误。(当我在我的机器中执行相同的代码时。)

你有一个额外的
加载()之前执行code>
。移除它,它就会工作。 只是注释了方法
oauth2\u login()
中的所有行,并安慰了一条要测试的消息及其工作

注意:您的格式不好,这对开发人员不好。请换一下

:)快乐编码:)


空白Cordova移动应用程序模板
/*下面的两条视口线相当于上面的元视口语句,是Windows所必需的*/
/*看http://www.quirksmode.org/blog/archives/2014/05/html5_dev_conf.html 及http://dev.w3.org/csswg/css-device-adapt/ */
@-ms视口{宽度:100vw;最小缩放:100%;缩放:100%;}@viewport{宽度:100vw;最小缩放:100%缩放:100%;}
@-ms视口{用户缩放:固定;最小缩放:100%;}@viewport{用户缩放:固定;最小缩放:100%;}
/*@-ms视口{用户缩放:缩放;最小缩放:100%;最大缩放:200%;}@viewport{用户缩放:缩放;最小缩放:100%;最大缩放:200%;}*/
.dispInline、.dispInlineLabel{
显示:内联网格;
边框底宽:0;
}
.dispInlineLabel{
最小宽度:自动;
}
.dispinle{
最小宽度:自动;
}
.clearFloats{
明确:两者皆有;
}
#tck_id
{
垫底:10px;
}
你好

函数oauth2_login() { console.log(“此处”); //var email=“abhigyan。gaurav@99rstreet.com"; //var密码=”abhigyan@123"; //var dataString=“User=“+email+”&Pass=“+password+”&login=”; //如果($.trim(用户名).length>0和$.trim(密码).length>0) // { //$.ajax({ //类型:“POST”, // //url:“http://35.201.138.23:8080/APIPRODUCTION/OperationJSP/operations.jsp", //数据:dataString, //克罗斯多
$(document).ready(function() {
  oauth2_login();
});
<!DOCTYPE html>
<html>
<!--
  * Please see the included README.md file for license terms and conditions.
  -->
<head>
    <title>Blank Cordova Mobile App Template</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">

    <!-- see http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-dont-forget-the-viewport-meta-tag -->
    <!-- <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1"> -->
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=no">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes, minimum-scale=1, maximum-scale=2"> -->
   <!-- <link rel="stylesheet" href="css/app.css">-->
    <style>
        /* following two viewport lines are equivalent to meta viewport statement above, and is needed for Windows */
        /* see http://www.quirksmode.org/blog/archives/2014/05/html5_dev_conf.html and http://dev.w3.org/csswg/css-device-adapt/ */
        @-ms-viewport { width: 100vw ; min-zoom: 100% ; zoom: 100% ; }          @viewport { width: 100vw ; min-zoom: 100% zoom: 100% ; }
        @-ms-viewport { user-zoom: fixed ; min-zoom: 100% ; }                   @viewport { user-zoom: fixed ; min-zoom: 100% ; }
        /*@-ms-viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }   @viewport { user-zoom: zoom ; min-zoom: 100% ; max-zoom: 200% ; }*/
        .dispInline, .dispInlineLabel{
    display: inline-grid;
    border-bottom-width:0;

}
.dispInlineLabel{
    min-width: auto;


}
.dispInline{
     min-width: auto;

}
.clearFloats{
    clear:both;
}

        #tck_id
        {
            padding-bottom: 10px;
        }


    </style>

    <!-- See explanation at the bottom of this file for info regarding placement of JS libraries. -->
    <!-- These library references (below) are just examples to give you the general idea... -->
    <!-- <script src="lib/mc/hammer.js"></script> -->
    <!-- <script src="lib/ft/fastclick.js"></script> -->
    <!-- <script src="lib/jq/jquery.js"></script> -->

<!--    <link rel="stylesheet" href="css/New.css" type="text/css">-->
     <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
    <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>


<body onload="oauth2_login()">
  <div data-role="page" id="paper">
      <div data-role="header" data-theme="b" data-position="fixed">
           <a href="#home" data-icon="arrow-l" data-iconpos="notext" data-direction="reverse" onclick="location.href='home.html'">Back</a>
         <h1>Hello</h1>
      </div>
      <div data-role="content">
          <p id="demo"></p>
          <div data-role="footer" data-position="fixed" data-theme="b"> <!-- fixed footer -->
              <div data-role="navbar"></div>
            </div>
        </div>
    </div>
    <script>

    function oauth2_login()
    {
        console.log("Here");
//      var email = "abhigyan.gaurav@99rstreet.com";
//      var password = "abhigyan@123";
//        var dataString="User="+email+"&Pass="+password+"&login=";
//        if($.trim(userName).length>0 & $.trim(password).length>0)
//        {
//            $.ajax({
//            type: "POST",
//
//            url: "http://35.201.138.23:8080/APIPRODUCTION/OperationJSP/operations.jsp",
//            data: dataString,
//            crossDomain: true,
//            cache: false,
//            beforeSend: function(){ $("#callAjax").html('Connecting…');},
//            success: function(data){
//                    var Data = $.parseJSON(data);
//                    if(Data.success=='1')
//                    {
//                        localStorage.login="true";
//                        //localStorage.email=email;
//                        var theName = $.trim($("#theName").val());
//                        var thePassword = $.trim($("#thePassword").val());
//                        localStorage.setItem("PMUsername",theName);
//                        localStorage.setItem("PMPassword",thePassword);
//                        localStorage.setItem("PMResponse",Data.success);
//                        alert("Login Successful");
//                        window.location.href = "home.html";
//                    }
//                    else if(Data.success=='0')
//                    {
//
//                        // document.getElementById("waiting").innerHTML = " ";
//                        alert("Wrong User");
//                        $("#callAjax").html('Login');
//                    }
//                }
//            });
//        }
        return false;
    }

    function Loading()
    {
        document.getElementById("waiting").innerHTML = "Loading...";
    }
</script>




    <script src="cordova.js"></script>

    <!-- for your event code, see README and file comments for details -->
    <script src="js/paper.js"></script>
    <!-- for your init code, see README and file comments for details -->
    <script src="js/init-app.js"></script>
    <!-- normalizes device and document ready events, see file for details -->
    <script src="xdk/init-dev.js"></script>

    <!-- IMPORTANT: Do not include a weinre script tag as part of your release builds! -->
    <!-- Place your remote debugging weinre script URL here, if it does not work above. -->
</body>
$(document).ready(function(){
    oauth2_login();
})
window.onload = function(){
     oauth2_login();
}
(function(){
     // code of oauth2_login goes here...
})();
<body onload="oauth2_login()"></body>