Ajax post Uncaught SyntaxError:意外的令牌ILLEGAL

时间:2013-12-06 13:24:11

标签: javascript jquery ajax

Uncaught SyntaxError: Unexpected token ILLEGAL 

找不到我错的地方。这是我的javascript代码:

$(function() {
        function Confirme(commentid,status){
            $.ajax({
                url: '/Management/Comment/Confirm',
                type: "POST",
                data: {"id": commentid,"status": status},
                success: function(response){
                }
            })
        }
    });

这是查看代码:

<input type="button" value="Onayla" onclick="Confirme(52a17bc02b94b1c418000001,0)"   class="btn btn-primary btn-sm">

不知道。

1 个答案:

答案 0 :(得分:6)

您的Confirme功能受其范围的限制。将其移到$(function()来电之外:

    $(function() {

    });

    function Confirme(commentid,status){
        $.ajax({
            url: '/Management/Comment/Confirm',
            type: "POST",
            data: {"id": commentid,"status": status},
            success: function(response){
            }
        })
    }

另外,正如阿德里亚诺指出的那样,你应该用引号包装你的纪念品:

<input type="button" value="Onayla" onclick="Confirme('52a17bc02b94b1c418000001',0)"   class="btn btn-primary btn-sm">