javascript - How to put nested php array into java script? -
i have code
$ref = addslashes(htmlspecialchars(json_encode($value))); echo '<script>var message_store_'.$key.'=$.parsejson('.$ref.');alert(message_store_'.$key.');</script>'; echo '<div class="message_entry" id ="message_entry'.$key.'" onclick="open_up_thread(\''.$ref.'\',\''.$key.'\');">'.$key.'</div>'; $recent = end($value); echo '<div id ="recent_message_log_entry'.$key.'"><div>'.$recent['message'].'</div><div>'.$recent['date_posted'].'</div></div>';
i facing problem storing array in global javascript variable. have div onclick event working fine array got converted wanted , function open_up_thread parsing encoded json object fine.
i need keep track of array before onclick event fired(after onclick easy converted).
so how achieve storing php array global javascript object json in php.
and reason why have onclick working not variable
thanks in advance
remove $.parsejson()
function , remove htmlspecialchars
, addslashes
:
$ref = json_encode($value); echo '<script>var message_store_'.$key.'='.$ref.';alert(message_store_'.$key.');</script>';
json format can directly parsed variable.
Comments
Post a Comment