使用js插入HTML

I try using ajax after submitting the form to get another

$(document).ready(function() 
    { $("#my_form").submit(function(event) 
        { event.preventDefault(); 
            $this = $(this); 
            $.ajax({ 
                type: "POST",
                data: $this.serialize(), 
                success: function(data) 
                { console.log(data); 
                    document.getElementById("my_form").replaceWith(data.form1);
                }, 
                error: function(data) 
                { console.log(data); 
                } 
            }); 
        }); 
});

but on the page the html code is inserted as a string, how can this be fixed?

Its look like your are replacing your subbmitting form, you can use jQuery .html() function to replace.

$(document).ready(function() 
    { $("#my_form").submit(function(event) 
        { event.preventDefault(); 
            $this = $(this); 
            $.ajax({ 
                type: "POST",
                data: $this.serialize(), 
                success: function(data) 
                { console.log(data); 
                    //document.getElementById("my_form").replaceWith(data.form1); //remove this.
                   //add below code
                   var parent=$("#my_form").parent();
                   parent.html(data.form1);
                }, 
                error: function(data) 
                { console.log(data); 
                } 
            }); 
        }); 
});