1

I'm try now over 5 hours to load dynamical generated code via AJAX in Bootstrap 4 Popover's. I still tried many variations found on Google but nothing get me the expected result.

I use jQuery 3.4.1.

I want to load the HTML form my file SucheBedarfspositionenAuslesen.php into a Bootstrap 4 Popover that is dynamically generated.

First here the source code:

$('.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;
    }
});

All code be correct fetched and shown if I set an alert() for debug. But the HTML can't be delivered to the return fetch_data . I still get my loading spinner. When I debug with a alert() after it the alert doesn't work. It's like there is a cut after the ajax routine.

When I try to return data in the success directly I get a "Uncaught TypeError: Cannot read property 'length' of undefined (sanitizer.js:93)".

Now on the end of my skills in this case. :) I hope you can help me to fix my issue.

Edit: Here the result I get in 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>

The Table is dynamical and can have more than two rows.

And here the source code:

<?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>
Johnnii360
  • 21
  • 4
  • Hi there, Maybe you can post your html as well? And did you check what is in `data`? Maybe you can post this as well. – Nebulosar Jul 19 '19 at 09:38
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – barbsan Jul 19 '19 at 10:09
  • @Nebulosar: Sure. Done. ;) – Johnnii360 Jul 19 '19 at 10:13
  • @barbsan: "I still tried many variations found on Google but nothing get me the expected result." If you can read and think of it you will understand. Stackoverflow was also on the Google results. And no it's no duplicate if you compare the codes. I using Bootstrap he is not. – Johnnii360 Jul 19 '19 at 10:13
  • So, did you try `return $.ajax` and in `success`: `return data` or `fetch_data = data; return fetch_data`? – barbsan Jul 19 '19 at 10:17
  • @barbsan: Sure, but `return $.ajax` results in `[object Object]`. All other in the above mentioned Uncaught TypeError, also when I add `responseText` on the end of the `$.ajax()`. – Johnnii360 Jul 19 '19 at 10:21
  • 1
    you may take a look to [Load a Bootstrap popover content with AJAX. Is this possible?](https://stackoverflow.com/questions/8130069/load-a-bootstrap-popover-content-with-ajax-is-this-possible) – gaetanoM Jul 19 '19 at 10:21
  • @gaetanoM: Still tried the most of the written solutions there. Nothing worked. – Johnnii360 Jul 19 '19 at 10:25
  • Btw. I will leaving office for today because this script is for work and I'm done for today. ;) Will read and try your solutions on next Monday. – Johnnii360 Jul 19 '19 at 10:32
  • No solution yet. – Johnnii360 Jul 22 '19 at 10:49
  • It's really, really strange... Many solutions, no progress. Bootstrap 4 might be more difficult than older versions. The issue is still by putting data into the popover. The data be fetched very well but it lacks still on the displaying. – Johnnii360 Jul 22 '19 at 13:35

0 Answers0