weixin_33711641 2016-11-01 13:29 采纳率: 0%
浏览 29

Phonegap Ajax不返回任何内容

i have tried to make a login in Phonegap and tried to connect it to my DB

it works when i use 'postman'

it alerts the correct email + password combi it alerts an empty string it logs and empty object

what am i doing wrong ? as im getting a reponse from the server but empty, it seems like my parameters are not getting transfered correctly

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

 ?>
  • 写回答

2条回答 默认 最新

  • csdn产品小助手 2016-11-01 14:03
    关注

    Just try the below code.

      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);
    
     ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法