我仍然是ajax和JavaScript的新手,所以很抱歉我错过了一些可能非常基本和直接的东西。
我正试着在onblur上提交一份表格。我正确地调用了函数,但我不确定如何引用表单中的变量。当我离开表单时,我在Firebug中看到它正在调用addNotes.php文件,但没有传递任何变量。
下面是JavaScript:
// Ajax to submit an edited post to the database.
function sendNotes() {
// we want to store the values from the form input box, then send via ajax below
var $form = $(this);
$.ajax({
type: "POST",
url: "includes/addNotes.php",
data: $form.serialize(),
success: function(){
}
}); // End .ajax function
return false;
} //End submit function()下面是HTML:
<form id="adminNotes" method="post" name="adminNotes" action="">
<textarea name="notes" id="notes" onblur="sendNotes()"></textarea>
</form> 发布于 2010-01-29 13:14:21
我还没有使用.serialize,但是尝试选择<form>,而不是您当前正在做的<textarea>。
在sendNotes函数中使用$("#adminNotes")而不是$(this)。
发布于 2010-01-29 13:11:08
我想通了。需要设置
var $form = $("form#adminNotes);https://stackoverflow.com/questions/2159915
复制相似问题