我有一个jQuery表单,每个步骤都很好,但它似乎没有提交。这是代码:
$(function(){
$("#demoForm").formwizard({
formPluginEnabled: true,
validationEnabled: true,
focusFirstInput : true,
textNext: 'Next',
formOptions :{
url: 'submit.php',
type: 'POST',
success: function(data){$("#status").fadeTo(500,1,function(){ $(this).html(responseText).fadeTo(5000, 0); })},
dataType: 'json',
beforeSubmit: function(data){$("#data").html("data sent to the server: " + $.param(data));},
resetForm: false
}
}
);
BeforeSubmit事件触发,但成功永远不会触发。 http://thecodemine.org/上的文档指向此处:http://jquery.malsup.com/form/#options-object,并建议malsup.com上的每个选项都可用于jQuery表单向导。
知道为什么状态div永远不会更新?
谢谢!
编辑:
更新了JS:
$(function () {
$("#demoForm").formwizard({
formPluginEnabled: true,
validationEnabled: true,
focusFirstInput: true,
textNext: 'Next',
remoteAjax: {
"cc": { // add a remote ajax call when moving next from the second step
url: 'submit.php',
type: 'POST',
dataType: 'json',
success: function (data) {
$("#status").fadeTo(500, 1, function () {
$(this).html(responseText).fadeTo(5000, 0)
});
}
}
},
formOptions: {
success: function (data) {
$("#status").fadeTo(500, 1, function () {
$(this).html(responseText).fadeTo(5000, 0);
})
},
dataType: 'json',
beforeSubmit: function (data) {
$("#data").html("data sent to the server: " + $.param(data));
},
resetForm: false
}
});
我现在在apache日志中看到脚本正在调用submit.php,但它似乎没有将响应放在页面上。
答案 0 :(得分:1)
我遇到了同样的问题 - 但设法让这个工作。关键是确保数据以JSON形式返回。
我正在使用node.js和express,所以只需要执行以下操作:
res.json({status: 'ok'});
答案 1 :(得分:0)
以非常可怕的方式解决了这个问题。创建了一个Ajax函数,并使用beforeSubmit选项调用它。我不推荐任何人这样做,但由于看起来成功形式选项不起作用,所以我真的只剩下要做的了。