Nature of data sent to client



  • The question was: how to better inform the client of the server of the nature of the data sent, for example, the data in one element and, if successful, in another.

    I'm thinking about using JSON as an answer where the properties are. type will describe the type of communication, but content - his contents. But I think this unfavourable model will affect productivity, because instead of habitual. echo We're gonna need to accumulate a response to the variable, then we're gonna have to work through it. json_encode()♪ If anyone has experience in dealing with such problems, tell me which way to look.



  • "The usual echo" is working slower than the inappropriate buffer. And it doesn't matter if you're using obfuscation or just writing it into a variable.
    With regard to the withdrawal of data in json: keep everything in range, then use json_encode() and echo + exit(if necessary). Example:

    if($_GET['type'] == 'ajax'){
        $data = array();
        if($a = $obj->get_some_data()){
            $data['type'] = 'success';
            $data['msg'] = $a;
        }
        else{
            $data['type'] = 'error';
            $data['msg'] = $obj->err_type;
        }
        echo json_encode($data);
        exit;
    }
    

    In fact, if you remove the verb through multiple echos, the above code may not work, it'll take half the page + json.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2