title: Django / Ajax not refreshing
body: <p>I have built a Save button. The user clicks the "Save" button to save a record to their collection. This changes the "Save" button text to "Saved". The user can then click on "Saved" to unsave the record.</p>
  
  <p>The user can Save the record succesfully and the ajax updates the html as expected by changing <code>id="likes"</code> to <code>id="unsave"</code>.</p>
  
  <p>The issue is that the ajax is not picking up the id="unsave" so is not routing to the <code>unsave_release</code> URL, it is routing to the <code>save_release</code> URL.</p>
  
  <p>Url examples</p>
  
  <p><a href="http://127.0.0.1:8000/save_release/?release_id=585197&amp;num_saves=14" rel="nofollow">http://127.0.0.1:8000/save_release/?release_id=585197&amp;num_saves=14</a>
  <a href="http://127.0.0.1:8000/unsave_release/?release_id=585197&amp;num_saves=14" rel="nofollow">http://127.0.0.1:8000/unsave_release/?release_id=585197&amp;num_saves=14</a></p>
  
  <p>Do I need to reset the ajax in some way after the user makes the initial Save?</p>
  
  <p><strong>Models.py</strong></p>
  
  <pre class="lang-py prettyprint-override"><code>@login_required
  def save_release(request):
  
      release_id = None
      num_saves = None
      username = request.user.username
      if request.method == 'GET':
          release_id = request.GET['release_id']
          num_saves = request.GET['num_saves']
  
      if release_id:
  
          insert = ChartsExtended(release_id=release_id,artist=username,url='Like',date='date',type='U',source='net')
          insert.save()
          num_saves = str(int(num_saves) + 1)
          return HttpResponse(num_saves)
  
  @login_required
  def unsave_release(request):
  
      release_id = None
      num_saves = None
      username = request.user.username
      if request.method == 'GET':
          release_id = request.GET['release_id']
          num_saves = request.GET['num_saves']
  
      if release_id:
  
          insert = ChartsExtended.objects.get(release_id=release_id,artist=username)
          insert.delete()
          num_saves = str(int(num_saves) - 1)
          return HttpResponse(num_saves) 
  </code></pre>
  
  <p><strong>ajax.js</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function() {
  
          // JQuery code to be added in here.
          $('#likes').click(function(){
              var release_id;
              var num_saves;
              release_id = $(this).attr("data-releaseid");
              num_saves = $(this).attr("data-numsaves")
              $.get('/save_release/', {release_id: release_id,num_saves: num_saves}, 
  
                  function(data){
  
                  $('#like_count').html(data + " people saved this");
  
                  // $('#likes').css({"background-color":"#FF0000"});
  
                  $('#likes').toggleClass("btn-info");
                  $('#likes').text('Saved!')
                  $('#likes').attr('id','unsave');
              });
          });
  
          //this unsaves a release from Release
          $('#unsave').click(function(){
              var release_id;
              var num_saves;
              release_id = $(this).attr("data-releaseid");
              num_saves = $(this).attr("data-numsaves")
              $.get('/unsave_release/', {release_id: release_id,num_saves: num_saves}, 
  
                  function(data){
  
                  $('#like_count').html(data + " people saved this");
  
                  // $('#likes').css({"background-color":"#FF0000"});
  
                  $('#unsave').toggleClass("btn-success");
                  $('#unsave').text('Save')
                  $('#unsave').attr('id','likes');
              });
          });
  </code></pre>
  
  <p><strong>release.html</strong></p>
  
  <pre><code>&lt;h3 id="like_count"&gt;{{dict_item.cnt}} people saved this&lt;/h3&gt;
  
  
    &lt;p&gt;&lt;button id="likes" data-releaseid="{{ dict_item.id }}" data-numsaves="{{dict_item.cnt}}" class="btn btn-xlarge btn-success release-follow-buttons" type="button"&gt;Save&lt;/button&gt;&lt;/p&gt;
  </code></pre>
  
  <p>which transforms into the following after the user clicks Save</p>
  
  <pre><code>&lt;p&gt;&lt;button id="unsave" data-releaseid="release_id" data-numsaves="num_saves" class="btn btn-xlarge btn-success release-follow-buttons btn-info" type="button"&gt;Saved!&lt;/button&gt;&lt;/p&gt;
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre class="lang-py prettyprint-override"><code>url(r'^save_release/$', views.save_release, name='save_release'),
  url(r'^unsave_release/$', views.unsave_release, name='unsave_release'),
  </code></pre>