我的网站中有一组复选框,用于运行下面发布的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))
{
?>
谢谢!
答案 0 :(得分:1)
问题不在于javascript,而是在服务器端。
$(".indexMain").load('indexMain.php?'+this.name+'=' + boxes.join("+"), function() {
$(".indexMain").fadeIn('slow');
$(".loadingItems").fadeOut(300);
});
您尝试从服务器加载内容,服务器以500响应。检查服务器日志并查看问题所在