Banner image SITE-LANGUAGE-en-ICON BROWSER-LANGUAGE--IMAGE
Content / help / jsdata .. concise-view << previous next >>

Passing an array to js from PHP

This code line can be inserted at the top of a view file. It will add a document.ready function() js code line that creates a javascript array and passes it into a javascript function.
The data passed is only an example of how to pass data this way.

$this->addReadyCode("params={uid:'2',timestamp:'43543224333',url: '/home' };setLogin(params);");

Use in document.ready setJSxx() functions

This method is more secure than leaving information in visible DOM elements for js to pick up

jsData - PHP Server side data made available for javascript

Just before a page is output, the contents of $BI->jsData are written to HTML DIVs so that server side data values are available to javascript, aJax etc.,

Passing Data from PHP to JavaScript

Sometimes Javascript needs to know about data help in $_SESSION on PHP. Biscuits provides some insensitive information about the current login etc., in HTML5 DIVs so that jquery can access them.

The jsdata is included in the HTML near the end of each page, just before the </body> end tag and looks like this:


<div style="display: none;" class="invisible">
<div id="jsdata-userlang">en</div>
<div id="jsdata-sitelang">en</div>
<div id="jsdata-userid">1</div>
<div id="jsdata-username">Guest</div>
</div>

Passing Data from JavaScript to PHP

Some client side information is not readily available on the server. For example the visitors timezone. This client side information might be useful to server side applications such as timetables and calendars, or event schedulers. It's nice to show event times in visitors own time. To make javascript data available to PHP we use ajax to pass the data into PHP as an argument when the document is ready.

When the $_SESSION data is first created, Biscuits generates a page with a javascript call to pass data from the client. ET_init('js')

Subsequently, this data is stored in the $_SESSION and so we don't need to ask javascript for it. Biscuits puts it back into the jsdata for viewing with View Source

Header Views

Header views contain scripts and so new pages should select a header view and stick to it throughout the whole site so that all pages have the same style.

Most View Files will have simple markup and will not contain scripts or CSS.





iBiscuits LOGO