Sending encoding response in json

后端 未结 1 842
忘了有多久
忘了有多久 2021-01-02 18:42

I am using a lot of jQuery in a project am working on.

I have a javascript function that makes an ajax request to a controller which returns data in JSON.

I

相关标签:
1条回答
  • 2021-01-02 19:21

    You MUST only use json_encode($data) once in a response, if you want to output more stuff, you need to merge your data into one array and send that.

    EDIT: To be clear, one way you could do it is like this:

    echo json_encode(array('pheeds' => $pheeds, 'res' => $res));
    

    Then in JS you will get an array with the keys "pheeds" and "res".

    Although it may be of little practical significance, I would also recommend doing this before you echo the json encoded string:

    header('Content-Type: application/json');
    
    0 讨论(0)
提交回复
热议问题