jQuery在POST后不更改textarea的值 [英] Jquery not changing value of textarea after POST
本文介绍了jQuery在POST后不更改textarea的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个页面,将textareas的值输入到MySQL数据库中.由于这是伪提交,因此在输入数据后,我手动将textarea的值更改为no.但是,按提交后,数据输入正确,但文本区域无法清除.根据答案的数量,HTML(下面)会被多次响应.
I have a page that inputs values of textareas into a MySQL database. Since this is a pseudo-submit I manually change the value of the textarea to nothing after the data is inputted. However, after I press submit, the data is inputted properly, but the textarea does not clear. The HTML (below) is echoed several times depending on the number of answers.
JavaScript:
JavaScript:
$('document').ready(function () {
$('.commentContainer').load('../writecomment.php');
$("form").on("submit", function (e) {
e.preventDefault();
var $form = $(this);
$.ajax({
"url": $form.attr("action"),
"data": $form.serialize(),
"type": $form.attr("method"),
"response": function () {
$('.commentContainer').load('../writecomment.php');
$('.commentBox').val(""); //this line doenst work
}
});
});
});
HTML:
<textarea class='commentBox' wrap='soft' name='comment'></textarea>
<input type='submit' value='comment' class='submitCommentBox'>
推荐答案
$.ajax
在其options对象中不使用response
参数.您应该使用
success: function () {
代替
"response": function () {
这篇关于jQuery在POST后不更改textarea的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文