title: How can I add the quantity from value to the cart sessions using ajax in django?
body: <p><strong>Problem</strong>
  <em>When i click on the add to cart button the url cart_add is triggered and the product value is added to it but the issue is that the quantity form value is not retrieved due to which the product is actually not added to the cart.</em>
  <em>The code i have written is as follows</em></p>
  <p><strong>Script</strong></p>
  <pre><code>$(document).on(&quot;click&quot;,&quot;.Id_submit&quot;,function(event){
        event.preventDefault();
        var selector = $(this).closest(&quot;.productID&quot;)
        console.log(selector.find(&quot;form&quot;).attr('action'))
        const form_data = {
          csrfmiddlewaretoken: $('#transactionIDValue input[name=&quot;csrfmiddlewaretoken&quot;]').val()
        }
        $.ajax({
          type : 'POST',
          url: selector.find(&quot;form&quot;).attr('action'),
          data: form_data,
          success: function()
          {
            alert(&quot;Product added to cart&quot;)
          }
        });
        
      });
  </code></pre>
  <p><strong>HTML</strong></p>
  <pre><code> &lt;form id='transactionIDValue' class=&quot;d-inline&quot; method=&quot;post&quot;&gt;
                {{cart_product_form}}
                {% csrf_token %}
                &lt;input type=&quot;submit&quot; class=&quot;btn btn-primary shadow px-5 py-2 Id_submit&quot; value=&quot;Add To Cart&quot;&gt;
  
  &lt;/form&gt;
  </code></pre>
  <p><strong>Views.py</strong></p>
  <pre><code>@require_POST
  @csrf_exempt
  def cart_add(request, product_id):
      cart = Cart(request)
      product = get_object_or_404(transactions, id=product_id)
      form = CartAddProductForm(request.POST)
      if form.is_valid():
          cd = form.cleaned_data
          print(cd)
          cart.add(product=product, quantity=cd['quantity'])
      else:
          print('error')
      print(cart)
  
      # request.session['items_total'] = cart.product.count()
      return HttpResponseRedirect(reverse('main:home'),'success')
  </code></pre>
  <p><strong>ISSUE</strong>
  <em>Now, the issue is that when the <code>{{cart_product_form}}</code> is called the quantity drop is set to the page but when i click on the add_to_cart the value from it is not added to cart, so i rechecked it even didn't even gets in the form validation check in the views. Can anyone help through this issue. This issue is only when i am using the add_cart function using ajax, but if i use it without ajax it works. All i want to know why is value from <code>{{cart_product_form}}</code> is not passed to the cart.</em></p>