How to select submit form with ajax, after using jQuery add elements method .after ()
Page .php on wordpress
<script>
$(document).on("click", "#solicitarServico", function() {
$(".simulador_de_precos_box").after("
<form accept-charset=\"UTF-8\" name=\"contact-form\" id=\"contact-form\" method=\"post\">
<input type=\"text\" name=\"name\" required>");
<button type=\"submit\" name=\"submit\" id=\"submit\">Send</button>
</form>");
});
</script>
<script>
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
var data = {
type: "POST",
context: this,
action: 'submit_form',
data: $( this ).serialize()
};
$.post(ajaxurl, data, function(response) {
console.log(response);
},'json');
});
</script>