Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.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 正在尝试连接到phonegap中的mysql数据库_Javascript_Android_Ajax_Jquery_Cordova - Fatal编程技术网

Javascript 正在尝试连接到phonegap中的mysql数据库

Javascript 正在尝试连接到phonegap中的mysql数据库,javascript,android,ajax,jquery,cordova,Javascript,Android,Ajax,Jquery,Cordova,我正在尝试在android上创建一个应用程序,让用户登录,我正在使用phonegap。 这是我的代码,但当我运行它时,我得到一个错误 这是我的index.html <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript" > function l

我正在尝试在android上创建一个应用程序,让用户登录,我正在使用phonegap。 这是我的代码,但当我运行它时,我得到一个错误

这是我的index.html

<html>
<head>
<script type="text/javascript"  src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript" >
function login() {
$(document).ready(function() {
var user = $("#user")[0].value;
var pass = $("#pass")[0].value;
$.ajax({
type:"GET",
url:"newlogin.php",
data: "user="+user+"&pass="+pass,
success: function(result){
if (result){
$("#message")[0].value = "Success "+result;
}
else {
$("#message")[0].value = "error";
}
}
});
});
}
</script>
<style type="text/css">
body{
margin:auto;
width:100%;
display: table;
background-color: #333;
}
form{
text-align: center;
height: 500px;
display: table-cell;
vertical-align: middle;
}
input{
font-size: 20px;
text-shadow: #ccc 2px 2px;
text-align: center;
}
input#message {
background-color: transparent;
border: 0;
color: white;
text-shadow: #5191C1 2px 2px;
}
</style>
</head>
<body>
    <form>
    <input type="text" size="25" id="user" onkeyup= "login()" />
    <br />
    <input type="text" size="25" id="pass" onkeyup= "login()"/>
    <br />
    <input type="text" size="25" id="message" value="hey" />
    </form>

</body>
</html>

函数登录(){
$(文档).ready(函数(){
var user=$(“#user”)[0]。值;
var pass=$(“#pass”)[0]。值;
$.ajax({
键入:“获取”,
url:“newlogin.php”,
数据:“user=“+user+”&pass=“+pass,
成功:功能(结果){
如果(结果){
$(“#message”)[0].value=“Success”+结果;
}
否则{
$(“#消息”)[0].value=“错误”;
}
}
});
});
}
身体{
保证金:自动;
宽度:100%;
显示:表格;
背景色:#333;
}
形式{
文本对齐:居中;
高度:500px;
显示:表格单元格;
垂直对齐:中间对齐;
}
输入{
字体大小:20px;
文本阴影:#ccc 2px 2px;
文本对齐:居中;
}
输入#消息{
背景色:透明;
边界:0;
颜色:白色;
文本阴影:5191c12px 2px;
}


这是它连接到的newlogin.php

<?php 
$user = $_REQUEST['user'];
$pass = $_REQUEST['pass'];

mysql_connect("localhost","root","sercet") or die(mysql_error());
mysql_select_db("book") or die(mysql_error());

$result = mysql_query("SELECT username,password,id FROM book_users WHERE username = '$user'");
while($row = mysql_fetch_array($result)) {
    if($pass == $row["password"]){
        echo $row["id"];
        } 
        else {
            echo "";
            }

    }

?>
我怀疑(因为您使用本地url调用“您的服务器”,并询问phonegap是否无法执行php),您在手机上部署了一个带有an的php文件。Phonegap无法执行php您需要一个运行php的服务器

更改您的代码:

url:“http://domainname/newlogin.php“


例如:本地的(http://192.168.43.104/new/newlogin.php)

这是个糟糕的问题。你有什么错误?谁知道从哪里开始查找呢?很抱歉,我试图添加一张显示错误的图片,但堆栈溢出不允许,但我确实重写了我的问题。