I have an error while mounting a dynamic menu with data coming from mysql.
Code that mounts the menu:
<div class="easyui-accordion" data-options="multiple:true" style="width:100%;">
<?php
$pdo = TConnection::open('teste');
$sql = "select distinct a.IdMenu,a.descricao as Nome
from Menu a inner join SubMenu b on b.IdMenu=a.IdMenu
inner join Camada c on c.idCamada=b.IdCamada
inner join CamadaOrganizacao d on d.IdCamada = c.IdCamada
inner join CamadaUsuario e on e.IdCamada = c.IdCamada
where e.IdUsuario = ? order by a.descricao asc";
$cat = $pdo->prepare($sql);
$cat->execute(array($user));
if ($cat->rowCount() >= 1):
echo '<div class="easyui-accordion" style="width:100%;">';
foreach ($cat->fetchAll(PDO::FETCH_ASSOC) as $res) :
$id = $res['IdMenu'];
echo '<div title="' . $res['Nome'] . '" data-options="iconCls:\'icon-ok\'" style="overflow:auto;padding:0;">';
$sql2 = "select IdSubMenu , '#principal' as abas,IdMenu, Descricao as Nome ,url from SubMenu where IdMenu = ? order by Nome asc";
$subMenu = $pdo->prepare($sql2);
$subMenu->execute(array($id));
if ($subMenu->rowCount() >= 1):
echo '<ul class="easyui-datalist" title="" lines="true" style="width:100%;">';
foreach ($subMenu->fetchAll(PDO::FETCH_ASSOC) as $linha) :
echo '<li>';
echo '<a href ="#" onclick="addTab('.$linha['abas'].','.$linha['Nome'] .','. $linha['url'] .');" >'. $linha['Nome'] .'</a>';
//echo '<a href="#" onclick="addTab('.$linha['abas'].'","'.$linha['Nome'] . '","' . $linha['url'] . ')">' . $linha['Nome'] . '</a>';
//echo '<a href="'.$linha['url'] . '">' . $linha['Nome'] . '</a>';
echo '</li>';
endforeach;
echo '</ul>';
endif;
echo '</div>';
endforeach;
echo '</div>';
endif;
?>
</div>
javascript function that opens the page in a div
function addTab(obj,title, url) {
if ($(obj).tabs('exists', title)) {
$(obj).tabs('select', title);
} else {
var hDiv = 0;
hDiv = $("#MenuLateral").height();
$(obj).height(hDiv);
var content = '<iframe name="conteudo" id="conteudo" scrolling="auto" frameborder="0" src=' + url + ' style=""></iframe>';
$(obj).tabs('add', {
title: title,
content: content,
closable: true
});
};
};
But clicking the link gives the following error, and I could not identify:
Uncaught SyntaxError: Invalid or unexpected token. (function (event) {addTab (# main, Organization, ./organization.php);})