0

I'm using Wordpress and I want to display a table, which contains pictures and buttons. This table should get loaded with a jquery load() method and put the result into a div.

I get the result, which I want, but it doesn't display in the div. Just here: here.

When I just put, for example, a H2 with text and without any php into the php file, then it gets displayed.

Script

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
function GetURLParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
        {
            return sParameterName[1];
        }
    }
}
jQuery(document).ready(function(){
    var $id = GetURLParameter('id');
    var urlGetItem = "getItems.php/?id=" + $id;
    jQuery('#load_surveys').load(urlGetItem);
});
</script>

HTML

<div id="load_surveys"></div>

PHP

<?php

include_once 'db.php';
require ('../wp-blog-header.php');

global $wpdb;
global $current_user;

get_currentuserinfo();
$userId = $current_user->ID;

$id = $_GET['id'];
$result = mysqli_query($conn,"SELECT * FROM f5_users JOIN COMPARISONFOLDER ON COMPARISONFOLDER.USER_ID = f5_users.ID JOIN ITEM ON ITEM.COMPARISONFOLDER_ID LIKE COMPARISONFOLDER.COMPARISONFOLDER_ID WHERE COMPARISONFOLDER.COMPARISONFOLDER_ID LIKE $id AND f5_users.ID LIKE $userId");

echo "<table border='1'>
<tr>
<th>Item</th>
<th>Delete</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo '<td><img src="data:image/jpeg;base64,'.base64_encode($row['ITEM']).'" width="500" height="auto"/></td>';
echo "<td><button type='button' onclick='deleteItem(".$row['ITEM_ID'].", $id)'>Testing Script</button></td>";
echo "</tr>";
}

echo "</table>";
?>
Lesmo
  • 19
  • 6
  • That particular request displays _in red_ in your screenshot, likely meaning the response did not come with a 200 OK status code, but an HTTP error instead. So jQuery thinks loading of this resource has actually failed, and therefor it does not insert anything into the page. – CBroe Mar 30 '21 at 07:55

1 Answers1

0

What do you get if you make console.log('id',$id) and console.log('url,urlGetItem)

jQuery(document).ready(function(){
    var $id = GetURLParameter('id');
    console.log('id',$id);
    var urlGetItem = "getItems.php/?id=" + $id;
    console.log('url,urlGetItem);
    jQuery('#load_surveys').load(urlGetItem);
});

PHP

$markup = "<table border='1'>
<tr>
<th>Item</th>
<th>Delete</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
$markup .= "<tr>";
$markup .='<td><img src="data:image/jpeg;base64,'.base64_encode($row['ITEM']).'" width="500" height="auto"/></td>';
e "<td><button type='button' onclick='deleteItem(".$row['ITEM_ID'].", $id)'>Testing Script</button></td>";
$markup .= "</tr>";
}

$markup .= "</table>";
echo $markup;
Bernhard Beatus
  • 1,191
  • 1
  • 5
  • 6