똑같은 삽질은 2번 하지 말자

PHP 에서 JSON으로 넘겨 javscript에서 받기 본문

카테고리 없음

PHP 에서 JSON으로 넘겨 javscript에서 받기

곽빵 2021. 10. 15. 18:14

xxx.php

public function toJSON()
{
  return $this->toISOString();
}

// 이하의 형태로 넘김
'xxx'  =>  xxx -> toJSON()

 

어디든 스크립트 코드가 되는곳,,

<script>
  const xxxData = JSON.parse(<?= json_encode($xxx); ?>)
</script>
Comments