下面的代码应该从提交的表单中捕获响应并将其显示在我的jsp页面的<div>
中,但这不会发生:
<script>
$( "#target" ).submit(function( event ) {
// Stop form from submitting normally
event.preventDefault();
// Get some values from elements on the page:
var $form = $( this ),
url = $form.attr( "action" );
// Send the data using post
var posting = $.post( url );
// Put the results in a div
posting.done(function( data ) {
var content = $( data ).find( "#content" );
$( "#result" ).append( content );
});
});
</script>
考虑到我的表格是:
<form method="post" action="cad_evento.html" id="target">
<p><input type="text" name="nome" placeholder="Nome" size=20 maxlength=40> </p>
<p><input type="text" name="descricao" placeholder="Descrição" size=30 maxlength=100> </p>
<h3>Periodo da Data</h3>
<p>inicio: <input name="data_inicial" placeholder="DD-MM-AAAA" pattern="\d{2}-\d{2}-\d{4}" /> </p>
<p>final: <input name="data_final" placeholder="DD-MM-AAAA" pattern="\d{2}-\d{2}-\d{4}" /> </p>
<h3>Periodo do Horário</h3>
<p>inicio: <input name="hora_inicial" placeholder="HH:MM:SS" pattern="\d{2}:\d{2}:\d{2}" /> </p>
<p>final: <input name="hora_final" placeholder="HH:MM:SS" pattern="\d{2}:\d{2}:\d{2}" /> </p>
<p><input type="text" name="duracao" placeholder="duração" size=20 maxlength=2> Minutos </p>
<p><button type="submit" class="btn btn-lg btn-primary">Cadastrar</button></p>
</form>
有人可以看到任何错误阻止脚本正确执行它应该做的事情吗?