Passing data from php to Jquery

前端 未结 6 2354
北恋
北恋 2020-12-21 19:44

I have all my javascript/jquery code in a file and include it into my page. Without having apache process js files as php what would be the best way to pass data from php to

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-21 20:21

    It's a good idea to have JS variables and objects with data, but another approach is to manage them through internal jQuery storage $.data()

    The advantages are obvious for non-trivial UI:

    • you can use DOM object as a namespace
    • encapsulation of internal data
    • logic and objects are "isolated"

    JS

    var pagedata = jQuery.data( document.body, '');
    var break_data = JSON.parge(pagedata)
    

提交回复
热议问题