需要定义一个HTML表单来使用jQuery ajax将字符串传递回我的MVC应用程序吗?

需要定义一个HTML表单来使用jQuery ajax将字符串传递回我的MVC应用程序吗?,jquery,ajax,Jquery,Ajax,我有一个/mysite/nameprocessor处理程序,我想使用jQuery ajax将字符串传递给它: <a href="#"><c:out value="${name}"/></a> 我是否需要将其包装在一个表单中,并像在Prototype中那样序列化表单,我认为这看起来像这样: <form action="/mysite/nameprocessor" method="post" onsubmit="new Ajax.Reque

我有一个
/mysite/nameprocessor
处理程序,我想使用jQuery ajax将字符串传递给它:

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

我是否需要将其包装在一个表单中,并像在Prototype中那样序列化表单,我认为这看起来像这样:

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

不,您不应该需要表单将值与jQuery一起发送回去。您可以简单地将数据添加到AJAX帖子中

$(function() {
 $('a').click( function() {
      $.post('/mysite/nameprocessor', { 'name' : $(this).text() }, function(data) {
           ... do something with the data returned from the post
      });
 });
});

不,您不应该需要表单将值与jQuery一起发送回。您可以简单地将数据添加到AJAX帖子中

$(function() {
 $('a').click( function() {
      $.post('/mysite/nameprocessor', { 'name' : $(this).text() }, function(data) {
           ... do something with the data returned from the post
      });
 });
});

我正处于写作的中间,我正处于写作的中间。