title: Get Value of Data from Form In Ajax Django Request
body: <p>I need to redirect my code to another page in Django url including primary key from my view.py after submission.</p>
  <p>I want to un-commitment these line of codes in my views.py</p>
  <pre><code>b = Business.objects.get(pk=business.pk)
  about = AboutBusiness.objects.create(business=b)
  </code></pre>
  <p>So I can get the value of about.id and add it to my ajax line like this, to redirect to this page;</p>
  <p>window.location.href = &quot;/seller/addaboutbusiness/about.id&quot;;</p>
  <p>model.py</p>
  <pre><code>class Business(models.Model):
  
      FLIP_TYPE = (
          ('1', 'Buy Out'),
          ('2', 'Partnership')
      )
  
      TYPE = (
          ('1', 'Business Name'),
          ('2', 'Sole Proprietorship'),
          ('3', 'Partnerships'),
          ('4', 'Limited Partnership'),
          ('5', 'Corporation'),
          ('6', 'Limited Liability Company'),
          ('7', 'Nonprofit Organization'),
          ('8', 'Cooperative')
      )
  
      user = models.ForeignKey(
          User, related_name='business', on_delete=models.CASCADE)
      flip = models.CharField(
          &quot;Type of Flipping&quot;, max_length=150, choices=FLIP_TYPE)
  
      name = models.CharField('Busniess Name', max_length=50)
  
      &quot;&quot;&quot; status = models.CharField('Registration Status',
                              max_length=50, choices=STATUS) &quot;&quot;&quot;
      status = models.BooleanField(&quot;Regsitration Status&quot;, default=True)
  
      registration = models.CharField(
          'Regsitraion Number', max_length=25, blank=True, null=True)
      t_business = models.CharField(
          &quot;Business Type&quot;, max_length=120, choices=TYPE)
      approval = models.BooleanField(default=False)
  
      created_at = models.DateField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
  
  class AboutBusiness(models.Model):
  
      &quot;&quot;&quot;Model definition for AboutBUsiness.&quot;&quot;&quot;
      business = models.ForeignKey(
          Business, related_name=&quot;about&quot;, on_delete=models.CASCADE)
      founder = models.CharField(
          &quot;OwnerShip Name&quot;, help_text=&quot;Seperate the name with comma&quot;, max_length=500)
      found = models.IntegerField(
          (&quot;When Found&quot;), choices=YEAR_CHOICES, default=datetime.datetime.now().year)
      about = models.TextField(&quot;About The Business&quot;)
      #industry = models.CharField(max_length=150)
      industry = models.ManyToManyField(Industry)
      location = models.CharField(&quot;Business Location&quot;, max_length=120)
      created_at = models.DateField(auto_now_add=True)
      updated_at = models.DateTimeField(auto_now=True)
  </code></pre>
  <p>views.py</p>
  <pre><code>def AddBusiness(request):
  
      if request.is_ajax() and request.method == 'POST':
          form = AddBusinessForm(request.POST or None)
          data = {}
          if form.is_valid():
  
              business = form.save(commit=False)
              user = request.user
              business.user = user
              business.save()
              #b = Business.objects.get(pk=business.pk)
              #about = AboutBusiness.objects.create(business=b)
  
              data['success'] = True
              return HttpResponse(json.dumps(data), content_type='application/json')
          else:
              data['success'] = False
              return HttpResponse(json.dumps(data), content_type='application/json')
      else:
  
          form = AddBusinessForm()
          return render(request, 'seller/addbusiness.html', {'form': form})
  </code></pre>
  <p>seller.js</p>
  <pre><code>$(document).on('submit', &quot;#post-form&quot;, function (event) {
      event.preventDefault();
      //alert(&quot;Ajax Called&quot;)
      var businessform = $(&quot;#post-form&quot;)
  
  
      $.ajax({
          url: &quot;addbusiness&quot;,
          type: &quot;POST&quot;,
          data: businessform.serialize(),
          datatype: &quot;json&quot;,
          header: { 'X-CSRFToken': '{% csrf_token %}' },
  
          success: function (response) {
              console.log($('#post-form').serialize());
              var success = response['success']
              if (success) {
                  alert(&quot;Form Valid and Created New Business....&quot;)
                  // window.location = &quot;//www.aspsnippets.com/&quot;;
                  window.location.href = &quot;/seller/addaboutbusiness/&quot;;
                  //window.location.replace(&quot;{% url 'successpayment' d.slug %}&quot;);
                  //businessform.reset()
              }
              else {
                  alert(&quot;The form is having issuess.....&quot;)
              }
  
          },
          failure: function (error) {
              alert(&quot;Error occur calling the Django view....&quot;)
          }
      })
  
  })
  </code></pre>