Jquery Ajax打电话给'点击'调用一个没有实现接口HTMLElement的对象

时间:2014-01-15 18:01:39

标签: javascript jquery ajax

我有以下javascript:

$('#edit_category').on('click','#btn_save_category_name',function(){
    currently_edit.text($('#txt_edit_category').val());

    edit_category_name(currently_edit,current_category_id);
    $('#edit_category').modal('hide')
})

function edit_category_name(name, id){
    $.ajax({
        type: 'POST',
        url: '/Category/edit_team_category',
        dataType: 'json',
        data: {
            request: 'ajax',
            name: name,
            id: id
        },
        success: function (data) {

        }
    });
}

现在,当我尝试这个时,我收到以下错误:called 'click' called on an object that does not implement interface HTMLElement.

但是,如果我评论功能线:edit_category_name(currently_edit,current_category_id);

一切正常。

谁能告诉我为什么会这样?

更新我的完整脚本

var mode = 'team';
var currently_edit = '';
var current_team_id = 0;
var current_category_id = 0;

jQuery(document).ready(function(){

    //Main click function for Team (selection of team)
    $('#team_wrapper').on('click', '.panel-heading', function () {
        if(mode === 'team'){
            current_team_id = $(this).siblings('small').text()
            title = $(this).find('.text-white').text();
            var i = 100;
            $('#span_search').hide();
            $('#btn_new_team').fadeOut();
            $('.col-lg-3').each(function(){
                $('.alt').toggle('slow');
                $(this).fadeOut(300,function(){
                    $(this).remove();
                });
            });
            $('#team_title').text('Select Category');
            $('#btn_new_category').delay(500).fadeIn();
            $('#selected_team_name').text(title);
            $('#selected').delay(695).fadeIn();
            $('#span_search').delay(500).fadeIn();
            $('#back').delay(500).fadeIn();
            generate_categories();

            mode = 'category';
        }else{
            $(this).next('div').find('a')[0].click();
        }
    })

    $('#team_wrapper').on('click', '.btn_administrate', function(){
        current_team_id = $(this).next('.team_id').text();
        load_team_members(current_team_id);
    });


    //Modal category:

    //create
    $('#btn_create_category').click(function(){
        add_category($('#txt_create_category').val());
        $('#group-form').modal('hide');
        $('#txt_create_category').val('');
    })

    // edit
    $('#team_wrapper').on('click','.team_category_edit',function(){
        current_category_id= $(this).next('input').val()
        edit_mode('txt_edit_category',$(this).closest("div").prev().find("h3"));
    })

    $('#edit_category').on('click','#btn_save_category_name',function(){
        currently_edit.text($('#txt_edit_category').val());

        edit_category_name(currently_edit,current_category_id);
        $('#edit_category').modal('hide')
    })

});


function edit_category_name(name, id){
    $.ajax({
        type: 'POST',
        url: '/Category/edit_team_category',
        dataType: 'json',
        data: {
            request: 'ajax',
            name: name,
            id: id
        },
        success: function (data) {
        }
    });
}
在这个例子中

    var current_team_id = 1;
var current_category_id = 2;

2 个答案:

答案 0 :(得分:5)

current_edit的价值是多少?我假设这是一个jQuery对象而不是文本值。请尝试以下方法。

edit_category_name(currently_edit.text(),current_category_id);

更新

正如Barmar所提到的,current_edit.text(...)根据您共享的内容无效。或许你打算做的是:

currently_edit = $('#txt_edit_category').val();

答案 1 :(得分:1)

尝试更改此行currently_edit.text($('#txt_edit_category').val());

currently_edit = $('#txt_edit_category').val();