Android 钛合金

Android 钛合金,android,titanium,titanium-mobile,titanium-alloy,Android,Titanium,Titanium Mobile,Titanium Alloy,我有一个钛合金应用程序的问题,这个问题只适用于Android,iOS也可以 所以我有一个查询数据库的登录表单,非常简单。但由于某些原因,它没有将参数传递给登录脚本 应用程序中的My JS函数,已在else语句上设置警报,以打印出$.email.value和密码值,这些值读取良好。但是当前的$response只是一个json,它将值显示为空?php表单也在下面。正如我所说,这在iOS上运行良好 function login(e) { //function to use HTTP to connec

我有一个钛合金应用程序的问题,这个问题只适用于Android,iOS也可以

所以我有一个查询数据库的登录表单,非常简单。但由于某些原因,它没有将参数传递给登录脚本

应用程序中的My JS函数,已在else语句上设置警报,以打印出$.email.value和密码值,这些值读取良好。但是当前的$response只是一个json,它将值显示为空?php表单也在下面。正如我所说,这在iOS上运行良好

function login(e) {
//function to use HTTP to connect to a web server and transfer the data.
var sendit = Ti.Network.createHTTPClient({
    onerror : function(e) {
        Ti.API.debug(e.error);
        alert('There was an error during the connection');
    },
    timeout : 100000,
});
//Here you have to change it for your local ip
sendit.open('GET', 'http://soyo.taylorhoganit.co.uk/post_auth.php');
var params = {
    email : $.email.value,
    password : $.password.value,
};
sendit.send(params);
//Function to be called upon a successful response
sendit.onload = function() {
    var json = this.responseText;  
    var response = JSON.parse(json);  
    if (response.logged == true)  
    {  
        var landing = Alloy.createController("landing").getView();
        $.index.close();
        landing.open();
        // Ti.App.Properties.setString('email', $.email.value);
        // Ti.App.Properties.setString('password', $.password.value);
        //alert("Username: " + response.username);
    }  
    else  
    {  
        alert($response);  
    }  
};
};  
PHP脚本

<?php  
// Connect to the database(host, username, password)  
$con = mysql_connect('replaced values');  
if (!$con)  
{  
echo "Failed to make connection.";  
exit;  
}  

$db = mysql_select_db('soyo');  
if (!$db)  
{  
echo "Failed to select db.";  
exit;  
}  

$email = $_POST['email'];  
$password = $_POST['password'];  

$sql = "SELECT * FROM users WHERE email = '" . $email . "' AND password = '" . $password .  "'";  
$query = mysql_query($sql);  

// If we find a match, create an array of data, json_encode it and echo it out  
if (mysql_num_rows($query) > 0)  
{  
$row = mysql_fetch_array($query);  
$response = array(  
    'logged' => true,    
    'email' => $row['email']  
);  
echo json_encode($response);  
}  
else  
{  
// Else the username and/or password was invalid! Create an array, json_encode it and echo it out  
$response = array(  
    'logged' => false,  
    'message' => $email + $password  
);  
echo json_encode($response);  
}  
?>  

您在警报中使用$response时出错。它是一个PHP变量,而不是JS

 var response = JSON.parse(json);
 // ... 
 alert($response); // Here should be just `response`

编辑:另一个问题是,在PHP中接受POST时发送GET请求,因此无法获取任何参数…

要显示警报时出错

您现在使用的是alert$response


从$response中删除$response并使用alertresponse;,它会正常工作

谢谢,我确实注意到了这一点并改变了它。谢谢不,如问题中所述,响应显示电子邮件和密码变量的空白值。当传递到php脚本时,它们似乎永远不会到达那里?如何更改开放的get to POST?使用GET发送这样的数据不是很安全。哇,我不觉得自己像个小丑吗!这已经奏效了。非常感谢,我肯定我需要睡觉了。。