我有一家多供应商商店,每个供应商都有自己的仪表板。仪表板中有一个产品选项卡可以查看他们的产品,并且可以对其进行编辑。我添加了一个搜索栏,以根据他们试图查找的关键字更新他们的列表。最近这个搜索栏卡在“请稍候..”上并且不更新列表。我尝试禁用最近所做的一些更新,但没有任何效果。另外,我在 Chrome 检查工具中显示了此错误。
未捕获(承诺中)类型错误:无法在“窗口”上执行“获取”:需要 1 个参数,但仅存在 0 个。 在 HTMLInputElement.onkeyup
这是产品列表的代码
<?php global $products;
global $edd_logs;
global $post;
?>
<?php echo EDD_FES()->dashboard->product_list_status_bar(); ?>
<div class="row">
<div class="col-12 col-md-6">
<h3 class="fes-headers" id="mayofes-orders-page-title"><?php echo EDD_FES()->helper->get_product_constant_name( $plural = true, $uppercase = true ) ?></h3>
</div>
<div class="col-12 col-md-6">
<div class="fes-cs-search_bar">
<form action="/" method="get" autocomplete="off">
<input type="text" name="s" placeholder="Search Products..." id="keyword" class="input_search" onkeyup="fetch()">
</form>
</div>
</div>
</div>
<div class="search_result" id="datafetch">
<ul>
<li>Please wait..</li>
</ul>
</div>
<div class="fes--list--style-p" id="fes-product-list">
<?php
if ( count( $products ) > 0 ) {
foreach ( $products as $product ) : ?>
<div class="product--flex--fes">
<div class = "fes-product-list-td fes--mob--image"><?php echo get_the_post_thumbnail( $product->ID, array( 100, 100,true ) ); ?></div>
<div class = "fes-product-list-td fes--mob--title"><?php echo EDD_FES()->dashboard->product_list_title( $product->ID ); ?></div>
<div class = "fes-product-list-td"><?php echo EDD_FES()->dashboard->product_list_status( $product->ID ); ?></div>
<div class = "fes-product-list-td"><?php $download = $edd_logs->get_log_count($product->ID, 'file_download'); echo ( is_null( $download ) ? '0' : $download ); ?> <?php esc_html_e('Downloads','mayosis'); ?></div>
<div class = "fes-product-list-td"><?php EDD_FES()->dashboard->product_list_actions( $product->ID ); ?></div>
<div class = "fes-product-list-td"><?php echo EDD_FES()->dashboard->product_list_date( $product->ID ); ?></div>
<?php do_action( 'fes-product-table-column-value', $product ); ?>
</div>
<?php
endforeach;
} else {
echo '<div><div class = "fes-product-list-td" >' . sprintf( _x( 'No %s found', 'FES lowercase plural setting for download','mayosis' ), EDD_FES()->helper->get_product_constant_name( $plural = true, $uppercase = false ) ) . '</div></div>';
}
?>
</div>
<?php EDD_FES()->dashboard->product_list_pagination();
下面是与上述代码相关的function.php代码
<script type="text/javascript">
function fetch(){
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: { action: 'data_fetch', keyword: jQuery('#keyword').val() },
success: function(data) {
jQuery('#datafetch').html( data );
}
});
}
</script>
<?php
}
// the ajax function
add_action('wp_ajax_data_fetch' , 'data_fetch');
add_action('wp_ajax_nopriv_data_fetch','data_fetch');
function data_fetch(){
$authorID = get_current_user_id();
$the_query = new WP_Query( array( 'posts_per_page' => -1, 's' => esc_attr( $_POST['keyword'] ), 'post_type' => 'download', 'author'=> $authorID ) );
if( $the_query->have_posts() ) :
while( $the_query->have_posts() ): $the_query->the_post();
global $products;
global $edd_logs;
global $post;
?>
<div class="product--flex--fes">
<div class = "fes-product-list-td fes--mob--image"><?php echo get_the_post_thumbnail( $product->ID, array( 100, 100,true ) ); ?></div>
<div class = "fes-product-list-td fes--mob--title"><?php echo EDD_FES()->dashboard->product_list_title( $product->ID ); ?></div>
<div class = "fes-product-list-td"><?php echo EDD_FES()->dashboard->product_list_status( $product->ID ); ?></div>
<div class = "fes-product-list-td"><?php $download = $edd_logs->get_log_count($product->ID, 'file_download'); echo ( is_null( $download ) ? '0' : $download ); ?> <?php esc_html_e('Downloads','mayosis'); ?></div>
<div class = "fes-product-list-td"><?php EDD_FES()->dashboard->product_list_actions( $product->ID ); ?></div>
<div class = "fes-product-list-td"><?php echo EDD_FES()->dashboard->product_list_date( $product->ID ); ?></div>
</div>
<?php endwhile;
wp_reset_postdata();
else :
echo "No Product Found";
endif;
die();
}
fetch() 函数是内置于 javascript 中的,因此您应该将函数重命名为其他名称,例如 fetchProducts()
<script type="text/javascript">
function fetchProducts(){
jQuery.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: { action: 'data_fetch', keyword: jQuery('#keyword').val() },
success: function(data) {
jQuery('#datafetch').html( data );
}
});
}
</script>
<input type="text" name="s" placeholder="Search Products..." id="keyword" class="input_search" onkeyup="fetchProducts()">