javascript 在未实现接口 HTMLElement 的对象上调用名为“click”的 Jquery Ajax

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21144954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 20:12:15  来源:igfitidea点击:

Jquery Ajax called 'click' called on an object that does not implement interface HTMLElement

javascriptjqueryajax

提问by Marc Rasmussen

I have the following javascript:

我有以下 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) {

        }
    });
}

Now when i attempt this i get the following error: called 'click' called on an object that does not implement interface HTMLElement.

现在,当我尝试此操作时,出现以下错误: called 'click' called on an object that does not implement interface HTMLElement.

But if i comment the function line out aka : edit_category_name(currently_edit,current_category_id);

但是,如果我注释掉函数行又名: edit_category_name(currently_edit,current_category_id);

everything works fine.

一切正常。

Can anyone tell me why this is happening?

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

Update my full script

更新我的完整脚本

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) {
        }
    });
}

in this example:

在这个例子中:

    var current_team_id = 1;
var current_category_id = 2;

回答by Michael Stewart

What is the value of currently_edit? I am assuming this is a jQuery object not a text value. Try the following instead.

current_edit 的值是什么?我假设这是一个 jQuery 对象而不是文本值。请尝试以下操作。

edit_category_name(currently_edit.text(),current_category_id);

Update

更新

As Barmar mentioned, currently_edit.text(...) is invalid based on what you have shared. perhaps what you meant to do was:

正如 Barmar 所提到的,根据您共享的内容,currently_edit.text(...) 是无效的。也许你的意思是:

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

回答by Merlin

Try changing this line currently_edit.text($('#txt_edit_category').val());

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

with this : currently_edit = $('#txt_edit_category').val();

有了这个 : currently_edit = $('#txt_edit_category').val();