jQuery意外令牌,在哪里?

时间:2014-02-27 09:36:48

标签: jquery ajax

我无法让这个简短的hello-world-like ajax功能工作几个小时。

Uncaught SyntaxError: Unexpected token :是所有错误消息。

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('td').click(function(){
        $.ajax(function(){
            type: 'POST',
            url: 'admin_ajax.php',
            data: {change_rights:8},
            success: function(msg){
                alert(msg);
            }
        });
    });
});
</script>

2 个答案:

答案 0 :(得分:6)

从Ajax请求中删除function()

$.ajax({
//-----^-
    type:   'POST',
    url:    'admin_ajax.php',
    data:   {change_rights:8},
    success: function(msg){
        alert(msg);
    }
});

Documentation : https://api.jquery.com/jQuery.ajax/

答案 1 :(得分:0)

像这样更改代码

 $(document).ready(function(){
    $('td').click(function(){

        $.ajax({
        type:   'POST',
        url:    'admin_ajax.php',
        data:   {change_rights:8},
        success: function(msg){
            alert(msg);
        }
    });
    });
});