0

I have a script on my page that takes a variable, but this variable is first created after a form is submitted. How can I create an AJAX call to my views after a user hits the submit button and then request the variable myID and then update my javascript on the html page with the value that it received?

The javascript that needs to be updated:

<script>
    stripe.redirectToCheckout({
      sessionId: "{{myID}}",
    }).then(function (result) {
      // Diplay result.error.message to your customer
    });
    </script>
  <script>
0

I am assuming that you have a view that returns JSON with the myID field and you are using ajax. You can make a post request and use the response to get the myID value.

$.post("{% url 'view-url-name' %}, form_data, function(data, status){
    stripe.redirectToCheckout({
    sessionId: data.myID,
}).then(function (result) {
  // Diplay result.error.message to your customer
});
  });

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.