title: AJAX on liferay portlets
body: <p>I am trying to send an AJAX request to a portlet, and it half works. I show you my code and after explain better:</p>
  
  <p>The jQuery AJAX:</p>
  
  <pre><code>jQuery("#operation").click(function() 
  {
      var url         = '&lt;portlet:resourceURL id="getDataResourceURL"&gt;&lt;/portlet:resourceURL&gt;';
      var operators   = jQuery('#result').html();
      jQuery.ajax({
          url:url,
          dataType: "json",
          data:{operators:operators},
          success: function(data)
          {
              jQuery('#result').html(data.result);
          }
  });
  </code></pre>
  
  <p>And the serveResource</p>
  
  <pre><code>@Override
  public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException, IOException 
  {
      String resourceId = resourceRequest.getResourceID();
      if (Validator.isNotNull(resourceId) &amp;&amp; resourceId.length() != 0 &amp;&amp; resourceId.equalsIgnoreCase("getDataResourceURL"))
      {
          //final String operators = resourceRequest.getParameter("operators");
          String operators = ParamUtil.getString(resourceRequest, "operators");
  
          _log.info("The data from AJAX are: " + operators);
  
          JSONObject jsonFeed = JSONFactoryUtil.createJSONObject();
  
  
          jsonFeed.put("result", 8);
          resourceResponse.setContentType("application/json");
          resourceResponse.setCharacterEncoding("UTF-8");
          resourceResponse.getWriter().write(jsonFeed.toString());
      }
  }
  </code></pre>
  
  <p>OK!! What it is working is the response, when I press the input with the id operation the div with id result loads an 8 (that the server response writting on jsonFeed.put("result", 8); The 8 is only for a test). What it is not working is the operators String on _log.info("The data from AJAX are: " + operators); that it is a null (if I use resourceRequest.getParameter("operators");) or an empty string (if I use ParamUtil.getString(resourceRequest, "operators");).</p>
  
  <p>What am I doing wrong? and what can I do to receive this value?</p>
  
  <p>Thank you very much.</p>
  
  <p>PS: On the client side, I tried too this:</p>
  
  <pre><code>jQuery.getJSON(url, {operators:operators}, function(data) 
  {
      jQuery('#result').html(data.result);
  });
  </code></pre>
  
  <p><sub><strong>PS:</strong> Also posted in <a href="https://www.liferay.com/community/forums/-/message_boards/message/47379844" rel="nofollow">Liferay forums</a></sub></p>