Currently having a problem getting JSON to include properly. I When I attempt to call .toJSONstring on an array it was giving me an error. So I resorted to just alerting the array out to the screen and here is what prints out:
key is: tmp1, value is: tmp1;
key is: tmp2, value is: tmp2;
key is: tmp3, value is: tmp3;
key is: toJSONstring, value is:
function () {
var a = ['['],
b,
i,
l = this.length,
v;
function p(s) {
if (b) {
a.push(',');
}
a.push(s);
b = true;
}
for (i = 0; i < l; i += 1) {
v = this[i];
switch (typeof v) {
case 'object':
if (v) {
if (typeof v.toJSONString === 'function') {
p(v.toJSONString());
}
} else {
p("null");
}
break;
case 'string':
case 'number':
case 'boolean':
p(v.toJSONString());
}
}
a.push(']');
return a.join('');
};
Now you can see it prints out the appropriate function code for the array prototyped version of the toJSONstring function. Which makes me think I am simply making some simple error in how I am including it.
Here is all of the relevant code below, except for JSON.js which I linked to
PHP index file:
you can see there is the single JS call
------------------------------------------------------------------------------------------------------------------
<?
2 require_once('includes.php');
3
4 $login = new login();
5 $login->user_login('xxxxxx','xxxxxx');
6 ?>
7 <LINK REL=StyleSheet HREF="./css/mylayout.css" TYPE="text/css" MEDIA=screen>
8 <head>
9 <? //<script type="text/javascript" language="javascript" src="js/json.js"></script>?>
10 <script src="js/json.js"></script>
11 <script language="javascript" src="js/mdp.js.php"></script>
12 <script>
13 <?
14 sajax_show_javascript();
15 ?>
16 </script>
17 </head>
18 <div id="main_nav">
19 <?
20 >-------echo '<button onclick="outside_call()">Save</button>';
21
22 ?>
23 </div>
24 <div id="sub_nav">
25 </div>
26 <div id="topToolBar">
27 </div>
28 <div id="basepage">
29 </div>
30 <div id="log">
31 </div>
----------------------------------------------------------------------------------------------------------------
JSON.js: litterally copy and pasted
--------------------------------------------------------------------------------------------------------------
http://json.org/json.js
-------------------------------------------------------------------------------------------------------------
mdp.js
--------------------------------------------------------------------------------------------------------------
1 <?
2 header("Content-Type: application/x-javascript\n");
3 ?>
4
5
6 function outside_call()
7 {
8 var test_array = new Array();
9 test_array['tmp1']='tmp1';
10 test_array['tmp2']='tmp2';
11 test_array['tmp3']='tmp3';
12 alert_array(test_array);
13 //var string;
14 //string = test_array;
15 //alert(string);
16 //alert_array(string);
17 }
41 function alert_array(inArray)
42 {
43 for (var i in inArray)
44 {
45 >-------alert('key is: ' + i + ', value is: ' + inArray[i]);
46 }
47 }
--------------------------------------------------------------------------------------------------------------