未捕获SyntaxError:在Codeignitor中使用jQuery Ajax时出现意外的令牌
在Codeignitor中使用jQuery Ajax时,出现错误“Uncaught SyntaxError:Unexpected token”。
这是我的代码:
function add_to_shopping_cart(base_url){
$.ajax(function(){
    url: base_url+'cart/add_to_cart',
    type: 'post',           
    data: $('#product_form').serialize(),
    dataType: 'html',
    success: function(html){
    }
});     
}
错误在行上“type:'post',”
我已经完成了数千次Ajax函数,并且无法看到是什么原因造成了这种感谢
  该代码没有意义。  删除$.ajax调用中的function()部分: 
function add_to_shopping_cart(base_url){
    $.ajax(/*no function() here*/{
        url: base_url+'cart/add_to_cart',
        type: 'post',           
        data: $('#product_form').serialize(),
        dataType: 'html',
        success: function(html){
        }
    });     
}
  你传递给ajax应该是一个对象初始值设定项,而不是一个函数。  如果它是一个函数,则内容需要是功能代码而不是一组属性初始值设定项。 
上一篇: Uncaught SyntaxError: Unexpected token when using jQuery Ajax in Codeignitor
