Usually when a value need to be passed to php
, it is a result from a button click or form submit. However, I am generating my values from a stripe handler
. How can I use AJAX
to POST
to .php
without button
or form
tag.?
This is what I have so far but no luck.
var handler = StripeCheckout.configure({
key: 'stripe_test_key',
image: "./img/my_image.png",
locale: 'auto',
token: function(token) {
alert(token.id);
$.ajax({
url: 'myphp.php',
type: 'POST',
data: { MyToken: token.id, MyEmail: token.email}
});
}
});
When I run this code, I am only able to see the alert which shows my token id. I have an echo
at the beginning of my php file but it does not show the message.
I am using Stripe Payments and I actually am clicking an img
to show
the handler
, but there has to be a way to pass my values to php
when I sucessfully get my token without having to detect an img
click event.