php通过JSON响应发布变量


php post variables through JSON response

有人知道如何通过用JSON封装的相同php响应将POST值发送到php文件吗?

到目前为止,我所做的是将用户名和密码发送到服务器端身份验证。但它会触发字段丢失的错误。所以我想在控制台的服务器端检查接收到的数据。

  if(isset($_POST['u_name']) && isset($_POST['u_pass'])){
       $username = $_POST['u_name'];
       $pass = $_POST['u_pass'];

  } else {
       // required field is missing
       $response["success"] = 0;
       $response["message"] = "Required field(s) is missing" + $_POST['u_name'] + $_POST['u_name']; // <--- this is my line 48
       // echoing JSON response
       echo json_encode($response);
  }  

但我收到了一个类似的错误

   <br />
   <b>Notice</b>:  Undefined index: u_name in <b>C:'xampp'htdocs'TestCordova'login_check.php</b> on line <b>48</b><br />
   <br />
   <b>Notice</b>:  Undefined index: u_name in <b>C:'xampp'htdocs'TestCordova'login_check.php</b> on line <b>48</b><br />
   {"success":0,"message":0}

试试这个

<?php
if(isset($_POST['u_name']) && isset($_POST['u_pass'])){
   $username = $_POST['u_name'];
   $pass = $_POST['u_pass'];
} else {
   // required field is missing
   $response["success"] = 0;
   $string = "";
   if(!isset($_POST['u_name'])
    $string = "User name";
   if(!isset($_POST['u_pass'])
    $string.= " Password";
   $response["message"] = "Required field(s) is missing ".$string ; // <--- this is my line 48
   // echoing JSON response
   echo json_encode($response);
}  
?>