views:

340

answers:

2

I am trying to pass json encoded values from a php script to a, GnuBookTest.js, javascript file that initiates a Bookreader object and use the values i have passed in via the variable i named "result".

The php script is sending the values like:

<div id="bookreader">
 <div id="BookReader" style="left:10px; right:10px; top:30px; bottom:30px;">x</div>
 <script type="text/javascript">var result = {"istack":"zi94sm65\/BUCY\/BUCY200707170530PM","leafCount":"14","wArr":"[893,893,893,893,893,893,893,893,893,893,893,893,893,893]","hArr":"[1155,1155,1155,1155,1155,1155,1155,1155,1155,1155,1155,1155,1155,1155]","leafArr":"[0,1,2,3,4,5,6,7,8,9,10,11,12,13]","sd":"[\"RIGHT\",\"LEFT\",\"RIGHT\",\"LEFT\",\"RIGHT\",\"LEFT\",\"RIGHT\",\"LEFT\",\"RIGHT\",\"LEFT\",\"RIGHT\",\"LEFT\",\"RIGHT\",\"LEFT\"]"}</script>
 <script type="text/javascript" src="http://localhost:8080/application/js/GnuBookTest.js"&gt;&lt;/script&gt;
 </div>
</div>

and in the GnuBookTest.js file i am trying to use the values like:

br = new BookReader();

// Return the width of a given page.
br.getPageWidth = function(index) {
     return this.pageW[index];
}

// Return the height of a given page.
br.getPageHeight = function(index) {
    return this.pageH[index];
}

br.pageW = JSON.parse(result.wArr);

br.pageH = JSON.parse(result.hArr);

br.leafMap = JSON.parse(result.leafArr);

//istack is an url fragment for location of image files
var istack = result.istack;
.
.
.

Using JSON.parse as i have written it above loads the Bookreader and uses my values correctly in a few web-browsers: Firefox, IE8, and desktop-Safari; but does not work at all in mac-Chrome, mobile-Safari, plus older versions of IE. Mobile safari keeps giving me a reference error msg: can't find variable: JSON. The other browsers just do not load the Bookreader and show the "x" instead, like they did not get the values from the php script.

Where is the problem?

+4  A: 

Older browsers don't have native JSON support. You'll likely have to include it manually.

Cory Larson
A: 

OK, i would close and accept this answer but i am not seeing anyway to do that. Perhaps the accept check-mark does not show-up for me because i was not a registered user when i asked the question? Sorry i could give you the points!

SuZi