title: How to pass data from ajax to django view?
body: <p>I have the following script for ajax. this gets the public key and sends all other detail to Stripe server for payment but I need to send the dynamic value of price to item_line.</p>
  <pre><code>fetch(&quot;/config/&quot;)
  .then((result) =&gt; { return result.json();})
  .then((data) =&gt; {
    // Initialize Stripe.js
    var data1 = $('#priceId').html();
  
  
    const stripe = Stripe(data.publicKey);
    // Event handler
    let submitBtn = document.querySelector(&quot;#submitBtn&quot;);
    if (submitBtn !== null) {
      submitBtn.addEventListener(&quot;click&quot;, () =&gt; {
        var d = $('#priceId').html();
        console.log(d) // this value need to send to my view...
        
      fetch(&quot;/create-checkout-session/&quot;)
        .then((result) =&gt; { 
          return result.json();
         })
        .then((data) =&gt; {
          // Redirect to Stripe Checkout
          return stripe.redirectToCheckout({sessionId: data.sessionId})
        })
        .then((res) =&gt; {
          console.log(res);
        });
      });
    }
  });
  </code></pre>
  <p>how can I pass and how can I catch in a view file?
  my current  view is:</p>
  <pre><code>
  @csrf_exempt
  def create_checkout_session(request):
      if request.method == 'GET':
          domain_url = 'http://localhost:8000/'
          stripe.api_key = settings.STRIPE_SECRET_KEY
          try:
              checkout_session = stripe.checkout.Session.create(
                  client_reference_id=request.user.id if request.user.is_authenticated else None,
                  success_url=domain_url + 'success?session_id={CHECKOUT_SESSION_ID}',
                  cancel_url=domain_url + 'cancel/',
                  payment_method_types=['card'],
                  mode='subscription',
                  line_items=[
                      {
                          'price': settings.STRIPE_PRICE_ID, # here need dynamic selected value
                          'quantity': 1,
                      }
                  ]
              )
              return JsonResponse({'sessionId': checkout_session['id']})
          except Exception as e:
              return JsonResponse({'error': str(e)})
  
  
  </code></pre>
  <p>please help me.</p>