dongping1012 2017-01-16 16:57
浏览 69

为什么json编码从php发送数据到javascript(Laravel)?

I have just read this question and noticed a lot of the answers showing json encoding. I'm just wondering why? Is it for some kind of security? So for instance in Laravel would this be the correct way to pull stuff in

var date = '{!! json_encode($event->date) !!}',
parseDate = JSON.parse(date);

//use parseDate here.

Sorry for making a whole new question, but I don't have the rep to comment on the original question :/

  • 写回答

3条回答 默认 最新

  • dsjuimtq920056 2017-01-16 17:19
    关注

    Generally, JSON is used to send data from the server to the browser when you want to retain it's structure. It is easy to parse in Javascript with the result being an array that matches the original array in the server language (like PHP). For simple, single values, it isn't really needed.

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!