Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript error unexpected identifier when trying to do jQuery AJAX call

I have this jQuery code:

<script type="text/javascript">
$(document).ready(function() 
{
    $('.vote_up').click(function() 
    {        
        alert ( "test: " + $(this).attr("data-problem_id") );
        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=+';

        $.ajax({
                type: "POST",
                url: "/problems/vote.php",
                dataType: "json",
                data: dataString,
                success: function(json)
                {           
                    // ? :)
                    alert (json);


                }
                error : function() 
                {
                    alert("ajax error");
                }
            });


        //Return false to prevent page navigation
        return false;
    });

    $('.vote_down').click(function() 
    {
        alert("down");

        problem_id = $(this).attr("data-problem_id");

        var dataString = 'problem_id='+ problem_id + '&vote=-';        

        //Return false to prevent page navigation
        return false;
    });    
});
</script>

I also have this link HTML:

        <p class="half_text"><?php echo $upvotes; ?> <strong><a class="vote_up" style="color: #295B7B; font-weight:bold;" href="#" data-problem_id="<?php echo $problem_id; ?>">Vote Up</a></strong> | <?php echo $downvotes; ?> <strong><a class="vote_down" style="color: #295B7B; font-weight:bold;" href="#" data-problem_id="<?php echo $problem_id; ?>">Vote Down</a></strong></p>

When I press the link, I get the Javascript console error "Syntax error: unexpected identifier"

You can reproduce this by clicking on a vote-up link here http://www.problemio.com

Any idea why this is happening and how to fix it?

like image 542
Genadinik Avatar asked Dec 05 '22 19:12

Genadinik


1 Answers

no comma between your success and error callbacks.

like image 138
hvgotcodes Avatar answered May 20 '23 14:05

hvgotcodes