weixin_33724059 2016-06-06 15:39 采纳率: 0%
浏览 38

应Ajax请求发出(Liferay)

I'm trying to pass this simple input on every keypress, to an ajax handler, and then to a controller:

<portlet:resourceURL var="resourceURL">
</portlet:resourceURL>

   <form id="busq" method="POST">
   <input id="busqueda" name="param1" type="text" onkeypress="buscar()"/>
   </form>

This is my ajax call. It seems to work ok: it sends the parameter in the POST request, and retrieves some data back from the server:

var busq = document.getElementById("busqueda").value;
    console.log("Searching for: "+busq);
    AUI().use('aui-io-request', function(A){
        A.io.request('${resourceURL}', {
               method: 'post',
               data: {
                   parametro: busq
               },
               on: {
                    success: function() {
                    console.log("RESULT: "+this.get('responseData'));
                   },
                   error: function(){
                       alert("Error");
                   }
              }
        });

    });

This is how I read it in the controller. It currently retrieves an empty string:

String datos = ParamUtil.get(req, "param2", StringPool.BLANK);

I tried all the following:

  • Using namespaces
  • Setting to false (current status).
  • Changing variable names.
  • Using ParamUtil.getString().
  • etc...

Nothing worked. I want to get the input value in my controller, so I can filter a search, but it never gets there (so I get all the query info without any filtering).

Any idea on what's wrong here?

  • 写回答

1条回答 默认 最新

  • weixin_33711641 2016-06-10 09:54
    关注

    You are usig wrong parameter name while getting value : String datos = ParamUtil.get(req, "param2", StringPool.BLANK);

    Try this code in your controller : String datos = ParamUtil.get(req, "parametro", StringPool.BLANK);

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程