Ajax 表单需要在提交后清除
Ajax Form needs to be cleared after submission
Ajax 表单需要在提交后清除。请如何只清除文本字段学生帖子,表单变量设置为发布 ajax 表单提交后的文本文本无需清除任何其他表单输入(假设它们已到位)。下面是我的工作 Ajax 表单
this.postMessage = function(user, text, uname, bb, callback){
var id = getUrlVars()["id"];
var uname=$("#uname").val();
var bb=$("#bb").val();
$.ajax({
'url': 'post.php?uname="+uname"',
'type': 'post',
'dataType': 'json',
'data': {
'id': id,
'mode': 'post',
'user': user,
'uname': uname,
'bb': bb,
'text': text
},
'success': function(result){
callback(result);
},
'error': function(e){
console.log(e);
}
});
};
};
var c = new Chatter();
$(document).ready(function(){
$('#formPost').submit(function(e){
e.preventDefault();
var user = $('#postUsername');
var text = $('#postText');
var err = $('#postError');
var id = getUrlVars()["id"];
var uname=$("#uname").val();
var bb=$("#bb").val();
c.postMessage(user.val(), text.val(), function(result){
if(result){
text.val('');
}
err.html(result.output);
});
return false;
});
在表单字段中,我将其设置为如下。
<form action="post.php" method="post" id="formPost" name="local_storage_form" >
School post:<textarea id="postText" name="postText" class"postText"></textarea><br>
<input type="submit" >
</form>
不确定字段的 id 是什么,但您可以将其添加到成功函数中:
success: function(result){
callback(result);
$('#postText').val(''); // might need to change the id...
},
jquery提供如果你想清除一个<input>
或<textarea>
标签使用.val('')
或其<div>
或任何使用.text('')
或.html('')
在 Ajax 上 成功调用 只需重置表单
document.getElementById("#formPost").reset();
参考:重置表单
相关文章:
- Angularjs:提交后清除表单无效
- 如何在表单提交后清除输入字段
- 清除按钮提交后的文本区域
- 在JSP中成功提交表单后清除表单字段
- 当我点击提交并尝试检查表单验证时,我的html表单将清除
- 点击提交后如何清除输入字段
- 如何在提交表单后清除以前的文本字段值而不刷新整个页面
- 点击'清除电子邮件输入;提交'按钮
- 提交 angularjs 后清除表单
- 提交后清除 PHP 表单
- 提交后清除表格
- 在 cakephp 1.3 中提交后清除表单
- 如何清除两个提交按钮的验证问题
- JavaScript -- 提交值后清除表单
- 在Javascript中,我可以在表单提交后“清除”浏览器(history -1)吗?
- JavaScript错误表单验证:提交时清除所有输入字段
- Ajax 表单需要在提交后清除
- 提交后清除表单中的文本字段
- 不需要的文件在IE中提交后清除文本框
- 使用 ajax 提交表单后清除所有表单元素