title: To implement like feature by ajax?
body: <p>My site is almost finished. However,one last thing being a problem. I want to implement a ajax liking feature.</p>
  
  <p>When the user will click on the button, the ajax should fire off and increment the value in the database and as well as on the display.</p>
  
  <p>My problem is everything is working fine except the ajax part, I have barely used ajax and not understanding how to implement it. Ajax should match the URL with the routing of node.js and display the result. Here is the relevant code.</p>
  
  <p>Here is my handlebars template:</p>
  
  <pre><code> &lt;div class="row"&gt;
  
      {{#each event}} {{#is this.event ../eventName }}
  
      &lt;div class="col s12 m3 13 al"&gt;
          &lt;div class="card "&gt;
              &lt;div class="card-image"&gt;
                  &lt;img src="/Small/{{this.imageId}}.JPG"&gt;
              &lt;/div&gt;
              &lt;div class="card-action"&gt;
  
                  &lt;a id="like_feature" href="/{{this.imageId}}/love" class="like"&gt;Love
                      &lt;i class="material-icons fav"&gt;favorite&lt;/i&gt;
                  &lt;/a&gt;
  
  
                  &lt;span class="rank"&gt;Rank: xxx
                      &lt;i class="material-icons eq"&gt;equalizer&lt;/i&gt;
                  &lt;/span&gt;
                  {{!-- {{this.imageId}} --}}
              &lt;/div&gt;
              &lt;div class="card-action"&gt;
                  &lt;span class="number_of_likes"&gt;Number of likes: {{this.vote}}&lt;/span&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  
      {{/is}} {{/each}}
  
  
  &lt;/div&gt;
  </code></pre>
  
  <p>This is my route which is handling the like feature</p>
  
  <pre><code>app.get('/:id/love', (req, res) =&gt; {
  console.log("Hitting");
  var image_Id = req.params.id;
  var query = {
      "imageId": image_Id
  }
  var update = {
      $inc: {
          vote: 1
      }
  }
  
  likeImformation.findOneAndUpdate(query, update, function (err, voted) {
      if (err) {
          res.status(404)
      } else {
          console.log(voted);
          res.send("loved");
      }
  });})
  </code></pre>
  
  <p>And this is what ajax I am able to build till now by reading tutorials, i am not understanding how to move after this</p>
  
  <pre><code>$(function(){
  $('#like_feature').click(function (e){
      e.preventDefault();
      $.ajax({
          url:'love',
          type:'GET',
          success:function(){
              console.log("it is been liked");
          },
          error: function () {
            console.log("Not been liked");
          }
      })
  })
  </code></pre>
  
  <p>})</p>