尝试执行jQuery AJAX调用时JavaScript错误意外标识符 [英] JavaScript error unexpected identifier when trying to do jQuery AJAX call
本文介绍了尝试执行jQuery AJAX调用时JavaScript错误意外标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个jQuery代码:
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>
我也有这个链接HTML:
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>
当我按下链接时,我收到Javascript控制台错误语法错误:意外标识符
When I press the link, I get the Javascript console error "Syntax error: unexpected identifier"
您可以通过点击此处的投票链接重现此信息 http:/ /www.problemio.com
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.
这篇关于尝试执行jQuery AJAX调用时JavaScript错误意外标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文