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条)

报告相同问题?

悬赏问题

  • ¥20 求会6sv辐射传输模型,辅导(可py6s🙏🏻有偿
  • ¥15 .xla后缀的文件拖到excel里什么内容也没有怎么办
  • ¥20 Workbench中Mechanical打不开、闪退是什么原因?
  • ¥240 MapReduce应用实践 学生课程
  • ¥15 hlss视频显示AUTHORITY_INVALID
  • ¥15 MAX9296A+MAX96717,美信gmsl解串有人做过吗?
  • ¥15 求帮我解决一下inode 爆满的问题(有偿)
  • ¥15 关于#vscode#的问题:布料滤波算法中C++实现pcl在Vscode中pcl库没有#include <pcl>
  • ¥15 fpga:ov5640采集tft显示
  • ¥100 python怎么连接wxSQLite3加密的数据库