Returning JSON from a PHP Script

前端 未结 18 1868
南方客
南方客 2020-11-21 04:59

I want to return JSON from a PHP script.

Do I just echo the result? Do I have to set the Content-Type header?

18条回答
  •  萌比男神i
    2020-11-21 05:46

    It is also good to set the access security - just replace * with the domain you want to be able to reach it.

     '1',
            'value1'=> 'value1',
            'value2'=> 'value2'
        );
    
    echo json_encode($response); 
    ?>
    

    Here is more samples on that: how to bypass Access-Control-Allow-Origin?

提交回复
热议问题