打开对话框,其中包含使用js/jquery从数据库遍历的php内容

打开对话框,其中包含使用js/jquery从数据库遍历的php内容,php,jquery,mysql,Php,Jquery,Mysql,我正在创建一个带有按钮的图像地图。按钮由php创建: while($pc = mysql_fetch_array($result)){ if ($pc['Online_Status']==0){ $class = 'workstation-offline'; } else{ $class = 'workstation-online'; } echo "\r\n\t\t\t".'<button class="'.$class.'" id="'.$pc['PCID'].'"

我正在创建一个带有按钮的图像地图。按钮由php创建:

while($pc = mysql_fetch_array($result)){
if ($pc['Online_Status']==0){
    $class = 'workstation-offline';
}
else{
    $class = 'workstation-online';
}


echo "\r\n\t\t\t".'<button class="'.$class.'" id="'.$pc['PCID'].'" title= "'.$pc['PCID'].'>';
}
while($pc=mysql\u fetch\u数组($result)){
如果($pc['Online_Status']==0){
$class=‘工作站脱机’;
}
否则{
$class=‘在线工作站’;
}

echo“\r\n\t\t\t”我将使用jquery ui模式对话框。()

您可以像这样动态加载数据。下面是按钮的单击处理程序,它将创建一个对话框,然后从服务器端页面加载数据:

$(document).ready(function () {
    $('.workstation-online,.workstation-offline').click(function () {
        var url = "put the url to obtain info from database here";
        var dialog = $('<div style="display:none" class="loading"></div>').appendTo('body');
            dialog.dialog({
                resizable: false,
                width: 400,
                height: 300,
                modal: true,
                closeText: '',
                close: function (event, ui) {
                    // remove div with all data and events
                    dialog.remove();
                }
            });
            dialog.load(
                url,
                function (responseText, textStatus, XMLHttpRequest) {
                    // remove the loading class
                    dialog.removeClass('loading');
                }
            );
            return false;
    });
});
$(文档).ready(函数(){
$('.workstation online,.workstation offline')。单击(函数(){
var url=“将从数据库获取信息的url放在此处”;
变量对话框=$('').appendTo('body');
对话({
可调整大小:false,
宽度:400,
身高:300,
莫代尔:是的,
closeText:“”,
关闭:功能(事件、用户界面){
//删除包含所有数据和事件的div
dialog.remove();
}
});
dialog.load(
网址,
函数(responseText、textStatus、XMLHttpRequest){
//删除加载类
removeClass('loading');
}
);
返回false;
});
});

Geeeeeee,谢谢!onclick函数现在正在工作!但我仍然不知道如何将数据放入对话框。我对js/jquery非常陌生。你可以使用一个php页面,从数据库获取数据并生成进入对话框窗口的html。完成后,只需分配url javascript变量I在我发布的代码中:var url='display_station_data.php?id='+this.attr('id');顺便说一下,我会将station id放在一个不同的属性中,然后是按钮的id…如下:
echo“\r\n\t\t”;
然后在click处理程序中,当您构建url时,我会使用
this.attr('stationId')
(我可能有语法错误,因为我对php不太了解。)我在代码中添加了这个:var url='traverse.php?id='pc['PCID']'';现在,对话框不再出现。我是否必须创建一个新的php文件以从数据库获取数据?您有一个javascript错误。id必须在引号之间。不要在那里使用php…因为此代码是从不同站点的每个按钮调用的。
var url='display_station_data.php?id='+this.attr('id');
是一条路要走。
<h3>"The ID of the Button"</h3>
<table>
    <tr>
        <td>IP Address</td>
        <td>pc['ipAddress']</td>
    </tr>
    <tr>
        <td>MAC Address</td>
        <td>pc['macAddress']</td>
    </tr>
    <tr>
        <td>Other Info</td>
        <td>pc['otherInfo']</td>
    </tr>
</table>
$(document).ready(function () {
    $('.workstation-online,.workstation-offline').click(function () {
        var url = "put the url to obtain info from database here";
        var dialog = $('<div style="display:none" class="loading"></div>').appendTo('body');
            dialog.dialog({
                resizable: false,
                width: 400,
                height: 300,
                modal: true,
                closeText: '',
                close: function (event, ui) {
                    // remove div with all data and events
                    dialog.remove();
                }
            });
            dialog.load(
                url,
                function (responseText, textStatus, XMLHttpRequest) {
                    // remove the loading class
                    dialog.removeClass('loading');
                }
            );
            return false;
    });
});