繁体   English   中英

Phonegap Ajax不返回任何内容

[英]Phonegap ajax returns nothing

我试图在Phonegap中进行登录,并尝试将其连接到我的数据库

当我使用“邮递员”时有效

它会警告正确的电子邮件和密码组合,并会警告它记录的空字符串和空对象

我究竟做错了什么 ? 当我从服务器收到响应但为空时,似乎我的参数没有正确传输

$("#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);

 ?>

除了Hamza Dairywala响应Access-Control-Allow-Origincontent-rype标头之外,请确保在config.xml中添加了Whitelist插件,并设置对*的访问权限,如下所示:

<access origin="*"/>
<plugin name="cordova-plugin-whitelist" spec="~1.3.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);

 ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM