javascript - Passing data from php to Jquery -
i have javascript/jquery code in file , include page. without having apache process js files php best way pass data php js script? right have hidden div on page echo out value using jquery text content , split variables. way of doing it? or there better way?
update
as mentioned prior, js code in .js file include webpage. way use php in scenario tell apache treat .js files php recongize php code inside .js file. dont want this.
html
<div id="pagedata" style="display:none;">data1<>data2</div>
js
var pagedata = $('#pagedata').text(); var break_data = pagedata.split('<>');
best practice matt mentions in comment above: use json. if you're going use jquery, can have php script call using either $.get()
or $.getjson()
. can find manual php json here: http://php.net/manual/en/book.json.php, , api reference jquery method $.getjson()
here: http://api.jquery.com/jquery.getjson/
hth.
Comments
Post a Comment