0

我的网站中有一组复选框,它们运行下面发布的 javascript。问题是,当我从复选框中选择一种颜色时,它不会执行任何操作,并且我在 Chrome 控制台中看到以下错误:

GET ../store/indexMain.php?color=Khaki 500 (Internal Server Error) jquery-1.7.2.min.js:4
send jquery-1.7.2.min.js:4
f.extend.ajax jquery-1.7.2.min.js:4
f.fn.extend.load jquery-1.7.2.min.js:4
(anonymous function) www.tahara.es:68
f.event.dispatch jquery-1.7.2.min.js:3
h.handle.i

这是js:

<script type="text/javascript">
    //http://jsbin.com/ujuse/1/edit
$(function() {
    $("input[type='checkbox']").on('change', function() {
        var boxes = [];
        // You could save a little time and space by doing this:
        var name = this.name;
        // critical change on next line
        $("input[type='checkbox'][name='"+this.name+"']:checked").each(function() {
            boxes.push(this.value);
        });
        if (boxes.length) {
            $(".loadingItems").fadeIn(300);
            // Change the name here as well
            $(".indexMain").load('indexMain.php?'+this.name+'=' + boxes.join("+"),
            function() {
                $(".indexMain").fadeIn('slow');
                $(".loadingItems").fadeOut(300);
            });

        } else {
            $(".loadingItems").fadeIn(300);
            $(".indexMain").load('indexMain.php', function() {
                $(".indexMain").fadeIn('slow');
                $(".loadingItems").fadeOut(300);
            });
        }
    });
});

从 indexMain.php 添加 PHP

<?php
$colors = $_GET['color'];
if ($colors != '')
 {
            $colors = explode(' ', $colors);
            $parameters = join(', ', array_fill(0, count($colors), '?'));
            $items = $con -> prepare("SELECT * FROM item_descr WHERE color_base1 IN ({$parameters})");
            $items ->execute($colors);
            $count = $items -> rowCount();

}
else 
{

        $items = $con -> prepare("SELECT * FROM item_descr ORDER BY date DESC");
        $items -> execute();
        $count = $items -> rowCount();


}

$row_count = 0;
echo "<div>Showing ".$count."items</div>";
while($info = $items->fetch(PDO::FETCH_ASSOC)) 
{

?> 

谢谢!

4

1 回答 1

1

问题不在于javascript,而在于您的服务器端。

$(".indexMain").load('indexMain.php?'+this.name+'=' + boxes.join("+"), function() {
    $(".indexMain").fadeIn('slow');
    $(".loadingItems").fadeOut(300);
});

您尝试从服务器加载某些内容,服务器以 500 响应。检查您的服务器日志,看看有什么问题

于 2013-01-16T00:45:20.233 回答