我正在开发一个android应用程序,使用PHP/MySQL从应用程序发送数据到服务器以注册/登录用户。我已经写了Javascript和PHP文件来发送和接收JSON数据并将其插入到MySQL数据库中。我遇到的问题是如何处理来自PHP的不同响应。处理不同的PHP回应之后,javascript http post请求
例:
<?php
//decode json object
$json = file_get_contents('php://input');
$obj = json_decode($json);
//variables
$user_firstname = $obj->{'user_firstname'};
$user_lastname = $obj->{'user_lastname'};
$user_email = $obj->{'user_email'};
$user_password = $obj->{'user_password'};
if([variables] != null){
//check for an existing email in db
mysql_query("Check if email exists");
if(email exist){
//pass a response to java file
return user_exists;
die();
}else{
//success
return success;
}
}
?>
我要的是为了与Android应用程序内的用户交互来处理这些不同的返回值。
+1有关http响应代码的好处。 – Asaph