正如 Headers 所说......
我的一些代码:有更多的输入,但我会把这个只是为了简化 .
<form name="frmCadastroPlano" id="frmCadastroPlano" class="form-horizontal" >
<input class="input-xlarge" id="inputNome" name="inputNome" type="text" value="" style="height: 26;">
<button type="submit" class="btn btn-primary" id="enviar">Cadastrar</button>
<button class="btn" name="clear" id="clear">Cancelar</button>
<div id="resposta"></div>
</form>
Ajax代码:
$("#frmCadastroPlano").submit( function(e) {
e.preventDefault();
dataString = $("#frmCadastroPlano").serialize();
$.ajax({
type: "POST",
url: "cadastroPlano.php",
data : dataString,
dataType: "html",
success: function(retorno) {
$("#resposta").html(retorno);
resetForm('frmCadastroPlano');
}
});
return false;
});
当我第一次按下按钮所有输入序列化的网址,如GET方法...示例url.php?inputNome = asdas&inputDuracao = asdasda&inputPreco = asdas ...然后表单被重置,我必须再次输入数据所以我最后可以提交...我已经看到了这个类似问题的另一个答案,但没有运气:/ Sry English .
OutPut with alert(dataString)inputNome = asda&inputDuracao = dsadas&inputPreco = dasdas
3 回答
你什么时候运行这个ajax代码?这看起来好像你没有在document.ready函数中运行它 . 试试这个
请注意:在浏览器中使用开发人员控制台(例如,在Chrome中使用Control Shift I)来查看网络上发生的事情(例如,GET或POST /哪些数据/ ...) . 这可能有助于您了解此类问题的根本原因 .
您可以查看this stackoverflow问题,因为在这种情况下它看起来与您的问题类似 .
尝试使用HTML5表单对象 -
你有另一个脚本运行吗?可能是chrome或firefox扩展?