Zerok
Zerok

Reputation: 227

Issue on Ajax request (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:

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?

Upvotes: 0

Views: 294

Answers (1)

Vinita Shah
Vinita Shah

Reputation: 118

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

Upvotes: 1

Related Questions