【问题标题】:jQuery load() not displaying echo table from php | wordpressjQuery load() 不显示来自 php | 的回显表WordPress
【发布时间】:2021-06-25 16:30:47
【问题描述】:

我正在使用 Wordpress,我想显示一个包含图片和按钮的表格。该表应该使用 jquery load() 方法加载,并将结果放入 div

我得到了我想要的结果,但它没有显示在 div 中。就在这里: here.

例如,当我将带有文本且没有任何 php 的 H2 放入 php 文件时,它就会显示出来。

脚本

<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>";
?>

【问题讨论】:

  • 该特定请求在您的屏幕截图中显示为 红色,这可能意味着响应没有带有 200 OK 状态代码,而是带有 HTTP 错误。所以jQuery认为这个资源的加载实际上已经失败了,因此它没有向页面中插入任何东西。

标签: php jquery wordpress load


【解决方案1】:

如果你制作 console.log('id',$id) 和 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;

【讨论】:

  • 我得到:id 246 url getItems.php/?id=246 这是正确的。我可以访问 php 文件并获取正确的数据。
  • 打个ajax调用可能会更好。
  • 也许这篇文章会对你有所帮助:stackoverflow.com/questions/43557755/…
  • 如果这对我有帮助的话。是因为问题稍后发生还是我错了?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-07
  • 2016-06-10
  • 1970-01-01
  • 1970-01-01
  • 2012-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多