开发者

Submit ajax onblur

I'm still new to ajax and JavaScript, so my apologies for missing something probably very basic and upfront.

I'm trying to submit an form onblur. I'm calling the function correctly, but I'm not sure how to reference the varia开发者_如何转开发bles from the form. When I move from the form, I see in Firebug that it's calling the addNotes.php file, but no variables are being passed.

Here's the 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()

Now here's the HTML:

<form id="adminNotes" method="post" name="adminNotes" action="">
    <textarea name="notes" id="notes" onblur="sendNotes()"></textarea>
</form> 


I haven't used .serialize, but try selecting the <form> instead of the <textarea> as you are currently doing.

Use $("#adminNotes") instead of $(this) in your sendNotes function.


Figured it out. Needed to set

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜