2010-01-29 58 views
0

我對ajax和JavaScript仍然很陌生,所以我很抱歉缺少一些可能非常基本和前沿的東西。提交ajax onblur

我正在嘗試提交表單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> 

回答

0

我沒有用過.serialize,但儘量選擇<form>代替<textarea>你正在做的事情。在您的sendNotes函數中使用$("#adminNotes")而不是$(this)

0

想通了。需要設置

var $form = $("form#adminNotes);