title: Grails: how to use jQuery & ajax to send data to controller
body: <p>I am trying to post a review for an event using ajax to avoid the page reload. This is my form for posting the review.</p>
  
  <pre><code>&lt;g:form &gt;
   &lt;g:textArea class="form-control" id="review" name="comment" value="${review?.comment}"&gt;&lt;/g:textArea&gt;
  
   &lt;span class="star-rating star-5"&gt;
       &lt;g:radio name="rating" id="rating-1" value="1"/&gt;&lt;i&gt;&lt;/i&gt;
       &lt;g:radio name="rating" id="rating-2" value="2"/&gt;&lt;i&gt;&lt;/i&gt;
       &lt;g:radio name="rating" id="rating-3" value="3"/&gt;&lt;i&gt;&lt;/i&gt;
       &lt;g:radio name="rating" id="rating-4" value="4"/&gt;&lt;i&gt;&lt;/i&gt;
       &lt;g:radio name="rating" id="rating-5" value="5"/&gt;&lt;i&gt;&lt;/i&gt;
   &lt;/span&gt;
   ...
   &lt;input type="submit" id="comment-ajax"/&gt;
  </code></pre>
  
  <p>My ajax:</p>
  
  <pre><code>  $( "#comment-ajax" ).click( function (){
      var eventID = document.getElementById('eventId').innerText;
  
        $.ajax( {
            url: "${createLink(controller:'review',action:'saveReview')}",
            type: "POST",
            data: { comment: $('.review-textarea').val(), rating: $('input[name=rating]:checked').val(), event:eventID  },
  
            success: function() {
               alert("success");
            },
            error: function() {
               alert("fail");
            }
        } );
    });
  </code></pre>
  
  <p>ReviewController:</p>
  
  <pre><code>def saveReview(Review review) 
  {
      User user = User.get(session.user.id)
      def comment = review?.comment
      def rating = review?.rating
  
      review.save flush:true
  }
  </code></pre>
  
  <p>Review domain:</p>
  
  <pre><code>class Review {
  
  String comment
  int rating
  
  static belongsTo = [event:Event, user:User]
  </code></pre>
  
  <p>The success alert is appearing, but no data is being inserted into my database.</p>