0

I have a set of checkboxes in my site that run the javascript posted below. The issue is that when I pick a color from the checkboxes, it does not do any action and I see the following error in the Chrome console:

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

Here is the 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);
            });
        }
    });
});

Adding PHP from indexMain.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)) 
{

?> 

Thanks!

3
  • 500 (Internal Server Error) There is a problem in the php script you are GETTING at /store/indexMain.php?color=Khaki -- Have you tried just going to the URL and see what happens? Commented Jan 16, 2013 at 0:43
  • 1
    Could you possibly go and set some of your 19 outstanding questions to answered? Commented Jan 16, 2013 at 0:43
  • @Zak - I posted the PHP part... would you mind taking a look? Commented Jan 16, 2013 at 2:28

1 Answer 1

1

The problem is not in the javascript, but rather in your server side.

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

You tried to load something from the server, and the server respond with 500. Check your server log and see what's the problem

Sign up to request clarification or add additional context in comments.

4 Comments

I just posted the PHP part... I can't find the issue
You need to check the server side log, because you get http 500 error, which is always triggered due to kind of server fail, e.g. error to access a database, or some program logic error caused exception
How can i check that log from Chrome?
you can't check server log from front end. You need to go to where indexMain.php is running and check the log on the console of that machine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.