title: Ajax succesfull call show div with form data
body: <p>views.py</p>
  
  <pre><code>def index(request):
      """"""""""""""
      registerform = UserRegisterForm(request.POST)
      createprofileform = UserCreateProfileForm(request.POST)                            
      if registerform.is_valid() and createprofileform.is_valid():               
          result = registerform.save(commit=False)
          result.set_password(request.POST['password'])        #set member password
          result.username = username               
          result.save()
          member.user_id = user.id
          member.member_id = result.id
          member.save()                                        #new member registration
          member_profile = UserProfile.objects.get(user=result.id)
          createprofileform = UserCreateProfileForm(request.POST, instance=member_profile)
          createprofileform.save()                             #create member profile                
          createprofileform = UserCreateProfileForm()
          member_save_msg = 'New member has been added.' 
          """"""""""""
      return render(request,'index.html',{ 'registerform': registerform,'createprofile': createprofileform,})
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>{% block main-content %}
  &lt;table width="98%" border="0" style="margin-left:0.7%;" cellpadding="0" cellspacing="0" id="rounded_table"&gt;
      &lt;tr &gt;
           &lt;td width="50%"&gt;Main Account Holder&lt;/td&gt;&lt;td width="50%"&gt;Authorised Reporters&lt;/td&gt;
      &lt;/tr&gt;
       &lt;tr id="main_account"&gt;
            &lt;td width="50%"&gt;All data related to main account holder comes here&lt;/td&gt;
       &lt;/tr&gt;
       &lt;tr id="authorised_reporter"&gt;
            &lt;td  width="100%" colspan="2"&gt;
             &lt;div id="authorisedreporter" {% if not registerform.errors %}style="display:none"{% endif %}&gt;
                  &lt;form method="post" action="." id="reporter-form"&gt;{% csrf_token %}
                  &lt;table  width="100%"&gt;
                    &lt;tr&gt;
                       &lt;td style="width:100px;"&gt;First name:&lt;/td&gt;&lt;td&gt;{{registerform.first_name}}&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                       &lt;td&gt;Last name:&lt;/td&gt;&lt;td&gt;{{registerform.last_name}} &lt;/td&gt;
                    &lt;/tr&gt;
                           """"""other form fields""""""""
                    &lt;tr&gt;
                       &lt;td colspan=2""&gt;&lt;p align="right"&gt;&lt;button type="submit" title="Save" &gt;Save &lt;img src="{{ STATIC_URL }}images/button-icon-ir-fwd.png" width="12" height="17" alt="" /&gt;&lt;/button&gt;&lt;/p&gt;
                       &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;/table&gt;&lt;/form&gt;
  &lt;/table&gt;
  {%endblock%}
  </code></pre>
  
  <p>The above views.py and index.html is for saving the new user entry.</p>
  
  <p>My html template is divided into 2 section,Main Account Holder tab and Authorised Reporters tab.Main Account Holder tab is for saving profile info and Authorised Reporters tab is for creating new user.on page load Main Account Holder tab will be active and user tab will be hidden.If user tab is selected,Main Account Holder tab will be hidden.Once the user is saved,the user details are displayed below, in below format. </p>
  
  <pre><code>{% for list in member_list %}
         &lt;tr class="ir-shade"&gt; 
          &lt;td style="width:120px;"&gt;&lt;span&gt;&lt;input type="submit" name="delete" value="{{list.0.id}}" class="delete_reporter" /&gt;&lt;/span&gt;&lt;button&gt; id="{{ list.0.id }}" class="openDiv"&gt;{{list.0.first_name|title}} {{list.0.last_name}}&lt;/button&gt;&lt;/td&gt;
         &lt;td style="width:410px;"&gt; {{list.0.email}} {{list.1.phone_daytime}} {{list.1.phone_mobile}}&lt;/td&gt;
         &lt;/tr&gt;
      {% endfor %}
  </code></pre>
  
  <p>What i actually want is Onclicking the <code>&lt;button&gt; id="{{ list.0.id }}" class="openDiv"&gt;{{list.0.first_name|title}} {{list.0.last_name}}&lt;/button&gt;</code>  saved user data should shown in same field in editable mode.i am passing the user id in button.On click the button,the data related to user id should shown in editable mode.</p>
  
  <p>js:</p>
  
  <pre><code>   $('.openDiv').click(function () {              
      var id = $(this).attr('id');  
      var csrf_token = $("#csrf_token").val();
      $.ajax({ 
         data:{
              csrfmiddlewaretoken: ('{{csrf_token}}'),                          
              id:id,                
              },
      type:'POST',
      url: '/setting/save-reporter/',
      success: function(data) {
          $('#authorisedreporter').html(data);
      }
    });
   });
  </code></pre>
  
  <p>The below views.py and html are written for showing the saved form instance.Now i can show the saved form instance and i am loading the instance into authorisedreporter div(please check in js and index.html).In this time if i kit save,it is creating new record,it is calling the views.py related to index method.I want to update and not save the record.</p>
  
  <p>save_reporter.html</p>
  
  <pre><code>&lt;form method="post" action="." id="{{ id }}"&gt;
      {% csrf_token %}
      &lt;table  width="100%"&gt;
          &lt;tr&gt;
              &lt;td style="width:100px;"&gt;First name:&lt;/td&gt;&lt;td&gt;{{form.first_name}}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Last name:&lt;/td&gt;&lt;td&gt;{{form.last_name}}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Daytime phone:&lt;/td&gt;&lt;td&gt;{{profile.phone_daytime}}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Mobile phone:&lt;/td&gt;&lt;td&gt;{{profile.phone_mobile}}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Email:&lt;/td&gt;&lt;td&gt;{{form.email}}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Password&lt;/td&gt;&lt;td&gt;{{form.password}}&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
             &lt;td colspan=2"&lt;p align="right"&gt;{% include "buttons/save.html" %}&lt;/p&gt;&lt;/td&gt;
          &lt;/tr&gt;&lt;/table&gt;&lt;/form&gt;
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def save_reporter(request):
      user = request.user
      id = request.POST.get('id')
      user = User.objects.get(pk =id)
      userprofile = UserProfile.objects.get(user=user.id)
      form = ReporterRegisterForm(instance=user)
      profileform = ProfilecontactForm(instance=userprofile)               
      return render(request, 'setting/save_reporter.html',
                     {'form': form,
                      'id':id,
                       'profile':profileform
                      })
  </code></pre>
  
  <p>I had explained my current issue i am facing,please have help me in doing this.Thanks</p>