title: Ajax not triggered in my Liferay portlet
body: <p>I have a MVCPortlet and I try to call ajax in a jsp page.</p>
  
  <p>My jsp is as follows:</p>
  
  <pre><code>&lt;%@include file="/html/init.jsp"%&gt;
  
  &lt;portlet:resourceURL var="updateRatAjax" id="updateRatAjax" &gt;&lt;/portlet:resourceURL&gt;
  
  
  &lt;script type="text/javascript"&gt;
  
  function selectRat(){
  
      var rat = new Object();
      rat.nom = $('#ratsList').val();
  
      alert(rat.nom + ' '/* + portletURL*/);
  
  
      $.ajax({
  
          url: "${updateRatAjax}" ,
          type: 'POST',
          dataType: 'json',
          data: JSON.stringify(article),
          contentType: 'application/json',
          mimeType: 'application/json',
  
          success: function (data) {
              alert('ajax' + article.nom);
              }
      });
  
      alert('end of function');
  }
  &lt;/script&gt;
  ....
  
      &lt;select  class="offset2 span4 form-control"  name=ratsList id = ratsList onchange="selectRat()"&gt;
          &lt;option&gt;1&lt;/option&gt;
          &lt;option&gt;2&lt;/option&gt;
          &lt;option&gt;3&lt;/option&gt;
      &lt;/select&gt;
  
      &lt;input  name = "selectedRat" id ="selectedRat"&gt;&lt;/input&gt;
  </code></pre>
  
  <p>My controler portlet resource is as folliws:</p>
  
  <pre><code>public class MainControllerPortlet extends  MVCPortlet {
  ...
      public void updateRatAjax( ResourceRequest request, ResourceResponse response)
              throws IOException, PortletException {
          System.out.println(" updateRatAjax");
  
      }
  }
  </code></pre>
  
  <p>I also tried to call the url this way into the js function:</p>
  
  <pre><code>  url:"&lt;%= updateRatAjax %&gt;",
  </code></pre>
  
  <p>and</p>
  
  <pre><code> var portletURL = "&lt;%= updateRatAjax %&gt;";
     url: portletURL,
  </code></pre>
  
  <p>no chance.
        <code>alert(rat.nom + ' '/* + portletURL*/);</code> 
  oes display
  but then nothing so the js method must be stopping when  $.ajax({...}) is called.</p>
  
  <p>The issue might have to do with the application not being able to map the resourceURL with the updateRatAjax method.
  In this project, the actionURL are correctly mapped to the controller's methods without I map them in web.xml nor I use any allocations.
  I took it that I don't need to map the portlet:resourceURL either, but I might be wrong there. First time I use portlet:resourceURL so I have no knowledge about them.</p>
  
  <p>thx in advance for your assistance.</p>
  
  <p>EDIT:
  following Sudakatux's answer, I changed the JS function to :
  ...</p>
  
  <pre><code> var portletURL = "${updateRatAjax}"; // "&lt;%= updateRatAjax %&gt;";//working  // 
    alert(rat.nom + '\n ' +   portletURL); //portletURL displays correctly with both options on previous line
  
      $.ajax({
  
          url: portletURL ,
          type: 'POST',
          dataType: 'text',
          cache: false,
          success: function (data) {
              alert('success ajax' );
              }, 
          error: function(http, message, exc) { 
             alert('error ajax'); 
         }
  
      });
  </code></pre>
  
  <p>Strangely enough, I get the success message but the controller method is never called :</p>
  
  <pre><code>public void updateRatAjax( ResourceRequest request, ResourceResponse response)
          throws IOException, PortletException {
  //public void updateRatAjax(ActionRequest request, ActionResponse response)        throws  PortalException, SystemException {
      System.out.println("MainController portlet : updateRatAjax");
  }
  </code></pre>