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);

    评论

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号