Need a HTML form defined to pass a String back to my MVC app using jQuery ajax?
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 l开发者_开发技巧ook 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;">
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
});
});
});
精彩评论