【问题标题】:play! framework 1.2.5 | Receiving and processing jquery ajax request on the Action controller玩!框架 1.2.5 |在 Action 控制器上接收和处理 jquery ajax 请求
【发布时间】:2012-12-30 15:30:28
【问题描述】:

我需要一些帮助来编写负责接收 POST 请求并处理它的操作的控制器部分..

客户端:

jQuery(function($) {    
$("#addPost").submit(function(event) {
    alert('addPost');
     event.preventDefault();

     var $form = $( this );      

     var url = $form.attr('action');                

     $.post(url , $("#addPost").serialize(),
        function (data ) {
                alert("success");
        });      

});       

});

#addPost 是一个表单,序列化后的表单数据如下:

post.type=new&post.title=yyy&post.body=newpost&post.weight=12

单击表单时,我可以看到调用转到了控制器上的 post 方法。我尝试以 Map 的形式接收,但结果为 null。

服务器端

public class Application extends Controller {

     ....   

public static void addPost(Map<String, String> req) {
     //req is null  
    }
}

【问题讨论】:

    标签: jquery playframework-1.x


    【解决方案1】:

    Yoyr addPost 控制器方法需要一个名为 req 的 HTTP (GET/POST) 参数,但您的参数称为 post.type、post.title、post.body 和 post.weight。

    【讨论】:

      猜你喜欢
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 2015-01-10
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 2018-02-28
      相关资源
      最近更新 更多