doubiaode0460 2015-07-11 17:15
浏览 76
已采纳

PHP MYSQL JSON Phonegap登录应用程序

I was trying to make a Phonegap App which has a simple login form, which should ideally connect to a PHP form, and retrieve the user role.

I would like to clarify following things:

  1. My Login Page, written in PHP works fine.
  2. When given the proper credentials as Get parameters, it returns the right JSON tags :

    {"update":true,"msg":"","role":"admin"}
    

Here is my Phonegap App HTML code. Kindly assist me on where I am going wrong. Assume that the username is username and password is password.

<!DOCTYPE html>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <form>
        <input id="username" name="username"placeholder="Email"></input>
        <input id="password" name="password"type="password" placeholder="Password"></input>
        <input type="button" value="Login" id="btnLogin"/>
    </form>
<div id="myDate"></div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
        <script>
$(document).ready(function()
{
$("#btnLogin").click(function()
{
    $( "#myDate" ).text( "Reached Here" );
  $.ajax({
url:"https://myurl.com/api-file.php",
type:"GET",
dataType:"json",
data:{username:"username",password:"password"},
ContentType:"application/json",
success:function(response)
{
  alert(JSON.stringify(response));
},
error: function(error)
{
  alert(JSON.stringify(error));
}
})
});
});
  </script>

    </body>
</html>

How the App should perform is, when I click the button, it calls the jquery code, which generates an AJAx request to the php file and retrieves a JSON string, which I intend to only pop as alert, as of now.

However, clicking the button does absolutely nothing.

I am hardcoding the username and password now but can and will take it from fields later on. Need to test this first before I do that though. Kindly assist on where am I going wrong.

  • 写回答

2条回答 默认 最新

  • douzhi1919 2015-07-15 06:06
    关注

    If nothing is happening then the problem is with the click function, otherwise the ajax call would have displayed an error. I say try getting rid of the $(document).ready(function() and put the js/jquery-2.1.4.min.js in the head (which by the way does not have a starting tag.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?