简体   繁体   English

未捕获的TypeError:在Ajax调用后无法读取未定义的属性'appendChild'

[英]Uncaught TypeError: Cannot read property 'appendChild' of undefined after Ajax call

I wanted to replace my html with the new Ajax response html but this error shows in the console and my script files are not loading correctly. 我想用新的Ajax响应html替换html,但是此错误在控制台中显示,并且我的脚本文件未正确加载。 Apparently this error comes in the file "jquery-1.10.1.min.js". 显然,此错误来自文件“ jquery-1.10.1.min.js”。 Following is my ajax code which I used to replace with the html in the success function. 以下是我的ajax代码,我曾经在成功函数中用html替换过。

$(function() {
         $('#addcustomer-done').click(function() {

       var formData = new FormData($('#submit_form')[0]);

       //---------------------- AJAX CALL 1 -----------------------------------------//
       $.ajax({
            // headers : {
                      // 'X-CSRF-Token' : document.getElementsByName('csrfmiddlewaretoken')[0].value
                  // },
            url : "/savecustomer/",
            type : "POST",

             data:formData,
             contentType: false,
             cache: false,
             processData: false,
             async: false,

             cache:false,
             contentType: false,
             processData: false,


            success : function(data) {
                alert(data);

                $("html").html("");
                $("html").html(data);
            }

I'm a beginner at ajax. 我是ajax的初学者。 Kindly guide me how to get rid of this error. 请指导我如何摆脱这个错误。 Thanks in advance. 提前致谢。

Dont clear the elements inside html tags. 不要清除html标记内的元素。 Use an element present in the dom to append the value. 使用dom中存在的元素来附加值。 Also remove async:false from your ajax. 还要从ajax中删除async:false Because ajax should run asynchronously. 因为ajax应该异步运行。

$(function() {
    $('#addcustomer-done').click(function() {
        var formData = new FormData($('#submit_form')[0]);
        $.ajax({
            url: "/savecustomer/",
            type: "POST",

            data: formData,
            success: function(data) {
                console.log(data);
                $("#id of element inside tab").append(data);
            }
        });
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTML DOM和Javascript:未捕获的TypeError:无法读取未定义的属性'appendChild' - HTML DOM and Javascript: Uncaught TypeError: Cannot read property 'appendChild' of undefined Sid.js:未捕获的TypeError:无法读取未定义的属性'appendChild' - Sid.js: Uncaught TypeError: Cannot read property 'appendChild' of undefined 未捕获的TypeError:调用getElementById()后无法读取null的属性'appendChild' - Uncaught TypeError: Cannot read property 'appendChild' of null after calling getElementById() 未捕获的类型错误:无法读取未定义的属性“调用” - Uncaught TypeError: Cannot read property 'call' of undefined 未捕获的TypeError:无法读取null的属性'appendChild'? - Uncaught TypeError: Cannot read property 'appendChild' of null? 未捕获的类型错误:无法读取 null 的属性“appendChild” - Uncaught TypeError: Cannot read property 'appendChild' of null 一个 div 容器产生“Uncaught TypeError: Cannot read property 'appendChild' of undefined” - one div-container produces "Uncaught TypeError: Cannot read property 'appendChild' of undefined" jQuery mobile:未捕获的TypeError:无法读取ajax调用中未定义错误的属性“ abort” - jquery mobile : Uncaught TypeError: Cannot read property 'abort' of undefined error in ajax call select2 ajax:未捕获的TypeError:无法读取未定义的属性“上下文” - select2 ajax : Uncaught TypeError: Cannot read property 'context' of undefined 未捕获的类型错误:无法使用 Laravel 和 AJAX 读取未定义的属性“” - Uncaught TypeError: Cannot read property '' of undefined using Laravel and AJAX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM