无法通过Bootstrap Popover中的AJAX加载动态生成的代码

时间:2019-07-19 09:30:50

标签: jquery ajax twitter-bootstrap bootstrap-4 bootstrap-popover

我现在尝试超过5个小时来通过Bootstrap 4 Popover的AJAX加载动态生成的代码。我仍然尝试了在Google上找到的许多变体,但是没有任何东西能让我得到预期的结果。

我使用jQuery 3.4.1。

我想将HTML格式的文件QuestBedarfspositionenAuslesen.php加载到动态生成的Bootstrap 4 Popover中。

首先是源代码

$('.popu').popover({
    html: true,
    placement: 'auto',
    trigger: 'hover',
    content: function(){
        var fetch_data = '<div class="d-flex justify-content-center"><div class="spinner-border" role="status"><span class="sr-only">Lade...</span></div></div>';
        var element = $(this);
        var id = element.attr("id");
        $.ajax({  
            url: "ajax/SucheBedarfspositionenAuslesen.php?nr=" + id,
            success: function(data)
            {  
                fetch_data = data;
            }
        });
        return fetch_data;
    }
});

如果我设置了alert()进行调试,则所有代码都将正确提取并显示。但是HTML无法传递到return fetch_data。我仍然可以得到加载微调器。当我使用alert()进行调试后,警报将无法正常工作。就像ajax例程结束之后一样。

当我尝试直接成功返回数据时,出现“未捕获的TypeError:无法读取未定义的属性'length'(sanitizer.js:93)”。

现在,在这种情况下,我的技能结束了。 :) 希望您能帮助我解决问题。

编辑: 这是我在data中得到的结果:

<table class="table">
<thead class="bg-info">
    <tr>
        <th scope="col">Bestellung</th>
        <th scope="col">Bezeichnung</th>
        <th scope="col" class="text-center">Anzahl</th>
        <th scope="col">Lieferant</th>
    </tr>
</thead>
<tbody>
        <tr>
        <th scope="row">14013MAIL</th>
        <td>Logitech Wireless Mouse</td>
        <td class="text-center">1</td>
        <td>Conrad</td>
    </tr>
        <tr>
        <th scope="row">14013TOOL</th>
        <td>Tastatur</td>
        <td class="text-center">1</td>
        <td>HP</td>
    </tr>
    </tbody>
</table>

表是动态的,可以有两行以上。

这里是源代码:

<?php
/**
 * Konfigurationsdatei einbinden
 */
include("../config.inc.php");
?>
<table class="table">
    <thead class="bg-info">
        <tr>
            <th scope="col">Bestellung</th>
            <th scope="col">Bezeichnung</th>
            <th scope="col" class="text-center">Anzahl</th>
            <th scope="col">Lieferant</th>
        </tr>
    </thead>
    <tbody>
    <?php
    /**
     * Filtere Vars
     */
    $Bedarfsnummer = filter_input(INPUT_GET, "nr", FILTER_SANITIZE_NUMBER_INT);

    /**
     * Auflisten der Einträge
     */
    $Bedarfspositionen = $mysqli->query("
        SELECT 
            id,
            Bedarfsnummer,
            Bestellung,
            Bezeichnung,
            Anzahl,
            Lieferant,
            REQ,
            RITM,
            Notiz 
        FROM 
            bedarfspositionen 
        WHERE 
            Bedarfsnummer = '".$Bedarfsnummer."'
        ") or die($mysqli->error);
    while($Bedarfsposition = $Bedarfspositionen->fetch_assoc())
    {
    ?>
        <tr>
            <th scope="row"><?php echo $Bedarfsposition['Bestellung'];?></th>
            <td><?php echo $Bedarfsposition['Bezeichnung'];?></td>
            <td class="text-center"><?php echo $Bedarfsposition['Anzahl'];?>    </td>
            <td><?php echo $Bedarfsposition['Lieferant'];?></td>
        </tr>
    <?php
    }
    ?>
    </tbody>
</table>

0 个答案:

没有答案