tags:

views:

18

answers:

1

I have a /mysite/nameprocessor handler that I want to pass a string to using jQuery ajax:

<a href="#"><c:out value="${name}"/></a>

Do I need to wrap this inside a form and serialize the form like in Prototype, which I think would look something like this:

<form action="/mysite/nameprocessor" method="post" 
     onsubmit="new Ajax.Request('/mysite/nameprocessor', 
     {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); 
     return false;">
+1  A: 

No you shouldn't need a form to send the value back with jQuery. You can simply add the data to the AJAX post.

$(function() {
 $('a').click( function() {
      $.post('/mysite/nameprocessor', { 'name' : $(this).text() }, function(data) {
           ... do something with the data returned from the post
      });
 });
});
tvanfosson
I was in the middle of writing just that.
BudgieInWA