Passing PHP JSON to [removed] echo json_encode vs echo json declaration

后端 未结 9 2171
猫巷女王i
猫巷女王i 2021-01-05 01:52

I\'m trying to create a common constants file to share between php and javascript, using JSON to store the constants. But I\'m wondering why pass the JSON from PHP to javasc

9条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 02:06

    The argument to json_encode() should be a PHP data structure, not a string that's already in JSON format. You use this when you want to pass a PHP object to Javascript.

提交回复
热议问题