Passing data from php to Jquery

前端 未结 6 2339
北恋
北恋 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:08

    HTML

    
    

    json_encode should be already in PHP 5.2. Otherwise look here http://www.json.org/

    JS

    var master = JSON.parse( $('pagedata').html() );
    // master.data1; // single
    // master.data2[0]; // 2a
    // master.data2[1]; // 2b
    

    To use JSON.parse you'll need json2.js from here https://github.com/douglascrockford/JSON-js.

提交回复
热议问题