The following is triggering a syntax error (unexpected identifier in Chrome, and missing ] after element list in Firefox):
infowindow.setContent('<h3>'+locale+' ('+hour+':00): $'+s.total+'</h3><img src="'+fname+'" onclick="open_dialog('+flot_data+');" style="cursor:pointer;" />');
Specifically, the '+flot_data+' in onclick="open_dialog('+flot_data+');". Removing this bit removes the syntax error.
Firebug points (literally) to flot_data which it represents with [object Object] (it points to the O in the second Object. The json was generated by PHP’s json_encode, so I don’t think the json is malformed (also I am elsewhere in this app able to successfully operate on all the parts of this object that I’m trying to use here).
I tried leaving in the onclick and commented out the contents of my open_dialog function to ensure the syntax error isn’t triggered inside it. And, I tried copying the contents of my open_dialog() function directly into the onclick like so:
onclick="$.plot($(\'#graph\'),'+flot_data+');"
(the onclick is encased in '' and uses "", so I had to use escaped single quotes)
I copy/pasted the data being passed to setContent and validated it in a fiddle. Why is the syntax incorrect here but not in the validation?
The problem is that flot_data is not a JSON string; it has apparently already been parsed into a JavaScript object, maybe by the AJAX call that retrieved it. You can’t concatenate an object with a string and expect to see JSON; the language has no idea what its original format was, and can’t convert it back.
You need to either use the raw JSON string and then parse it inside of open_dialog, or a much better idea would be to avoid the inline handler altogether, and attach the click listener in your script, using jQuery’s
.click(function).