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?
no comma between your success
and error
callbacks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With