我试图在Phonegap中登录并尝试将其连接到我的数据库
当我使用'postman'
时它会起作用它会提醒正确的电子邮件+密码组合 它会提醒一个空字符串 它记录和空对象
我在做错了什么?因为我从服务器获得响应但是空了,看起来我的参数没有正确传输$("#submit").click(function() {
var email = $("#username").val();
var password = $("#password").val();
if (email == '' || password == '') {
} else {
$.ajax({
type: 'GET',
url: 'http://xxxxx.php',
crossDomain: true,
data: {
email: 'email',
password: 'password'
},
dataType: 'json',
success: function(JSONObject) {
alert(email + password);
alert(JSON.stringify(JSONObject));
console.log(JSONObject);
},
error: function() {
//console.error("error");
alert('Not working!');
}
});
}
});
的login.php
<?php
//Importing Database Script
require_once('dbConnect.php');
//GETS
$email=$_GET['email'];
$pass=$_GET['password'];
//Creating sql query
$sql = "SELECT * FROM `customerdata` WHERE customerNo = '$email' AND customerName = '$pass'";
//getting results
mysqli_set_charset($con,'utf8');
$r = mysqli_query($con,$sql);
//creating a blank array
$result = array();
//looping through all the records fetched
while($row = mysqli_fetch_array($r)){
//Pushing information in the blank array created ID, deviceID, terminalnumber, qrcode, cloakroomsection, cloakroomnumber, delivered, collected
array_push($result,array(
"customerName"=>$row['customerName'],
"customerNo"=>$row['customerNo']
));
}
//$finalresult= array();
//$finalresult['1'] = $result;
//Displaying the array in json format
echo json_encode($result);
//echo json_encode($encoded_rows);
mysqli_close($con);
?>
答案 0 :(得分:1)
除了Hamza Dairywala响应Access-Control-Allow-Origin
和content-rype
标题之外,请确保在您的config.xml中添加了Whitelist插件并设置*的访问权限:
<access origin="*"/>
<plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
答案 1 :(得分:0)
试试以下代码。
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
//Importing Database Script
require_once('dbConnect.php');
//GETS
$email=$_GET['email'];
$pass=$_GET['password'];
//Creating sql query
$sql = "SELECT * FROM `customerdata` WHERE customerNo = '$email' AND customerName = '$pass'";
//getting results
mysqli_set_charset($con,'utf8');
$r = mysqli_query($con,$sql);
//creating a blank array
$result = array();
//looping through all the records fetched
while($row = mysqli_fetch_array($r)){
//Pushing information in the blank array created ID, deviceID, terminalnumber, qrcode, cloakroomsection, cloakroomnumber, delivered, collected
array_push($result,array(
"customerName"=>$row['customerName'],
"customerNo"=>$row['customerNo']
));
}
//$finalresult= array();
//$finalresult['1'] = $result;
mysqli_close($con);
header('content-type: application/json; charset=utf-8');
//Displaying the array in json format
echo json_encode($result);
//echo json_encode($encoded_rows);
?>