We are on the right way.
With your suggestion Jim, I get (also when asking for the variable on the Javascript console):
[{'name': 'Paul', 'age': 31, 'city': 'Ulm'}, {'name': 'Otto', 'age': 23, 'city': 'Friedrichshafen'}]
Having this code:
#-*- coding: utf-8 -*-
# is this uff-8 coding wrong as I have differences between html and js variable, embedded through py4web
[[extend "layout.html"]]
<html>
[[
pyjsondata = [{
"name": "Paul",
"age": 31,
"city": "Ulm"
},
{
"name": "Otto",
"age": 23,
"city": "Friedrichshafen"
}];
]]
<!-- var htmljsonvar = [[=pyjsondata]] // not needed, substituted through: Html Variable: jsonvar -->
<head>
<title>DOM</title>
</head>
<body>
<p id="one">VARIABLE-Text to be displayed with Javascript in Pop-Up Window </p>
<p id="jsonvar">[[=pyjsondata]] </p>
<p> -------------------------- </p>
<p>This is the welcome message.</p>
<p>Technology </p>
<p>This is the technology section.</p>
<script type="text/javascript">
//demo example, to show principle
var text = document.getElementById("one").innerHTML;
alert("The first heading is: " + text);
//data got transferred from Python to HTML and them from HTML to Javascript, looks good right now
var jsonscrvar1 = document.getElementById("jsonvar");
alert(jsonscrvar1);
//data got transferred from Python to HTML and them from HTML to Javascript, looks good right now
var jsonscrvar2 = document.getElementById("jsonvar").innerHTML;
alert(jsonscrvar2);
//data gets directly transferred from python to Javascript, works in priciple but need to be set correct or tidied through regexp.
var jsonscrvar9 = "[[=pyjsondata]]";
alert(jsonscrvar9);
</script>
</body>
</html>
then (with 'innerHTML'):
jsonscrvar2 looks best: [{'name': 'Paul', 'age': 31, 'city': 'Ulm'}, {'name': 'Otto', 'age': 23, 'city': 'Friedrichshafen'}]
works best. But on other structure I get the error: 'SyntaxError: Unexpected EOF' (through the Javascript console, see below).
The least necessary code (from you Jim) would be best. But on other structure like a data frame very often I get
var dfdatajsvar9 = " x y
0 A 14
1 B 15
2 C 13
3 D 16
4 E 11
5 F 13
6 G 19
7 H 17
8 I 12";
SyntaxError: Unexpected EOF
And the innerHTML command makes:
"{
\"config\": {
\"view\": {
\"continuousHeight\": 300,
\"continuousWidth\": 400
}
},
\"data\": {
\"name\": \"data-c29c100fe8b1be6abd3ee935e9c8697d\"
},
adds backslashes to the promising structure.
{
"config": {
"view": {
"continuousHeight": 300,
"continuousWidth": 400
}
},
"data": {
"name": "data-c29c100fe8b1be6abd3ee935e9c8697d"
},
Also I had seen this:
{
"config": {
"view": {
"continuousHeight": 300,
"continuousWidth": 400
}
},
"data": {
"name": "data-c29c100fe8b1be6abd3ee935e9c8697d"
},
Best would be to get rid of the Syntax Error unexpected EOF and use the simple command Jim suggested. Another option would be more coding with innerHTML and them regular expressions to get rid of ''' or ‘\‘ and '"'
Don't spend too much time. But if there is an easy solution (maybe just another character set) or a place where I can investigate further it would help.
As a side issue, the transfer from [[py4web yatl]] to HTML variables work fine.
Having py4web/python as the 'common denominator' with simple ways to get HTML or JS variables (maybe other languages) and vice versa would be best.
I have not investigated jQuery.