Paul Southcott
asked on
send data and load file from javascript to php
Hi
I have data returned (i presume it is in 'checkout;paymentResult' )
I need to send data to a phpfile 'sum.php' and load the php file
How would I do that ??
I have data returned (i presume it is in 'checkout;paymentResult' )
I need to send data to a phpfile 'sum.php' and load the php file
How would I do that ??
<script>
//render the form ui providing a configuration object
PaymentCard.mount({checkoutId: "<?= $checkoutId ?>","fields_placeholders": {
"card_number": "Card number",
"cvv": "CVV",
"expiry_date": "Expiry date",
"pay_now": "Pay £ <?= $amount ?> Now" }});
//listen to checkout processing result and handle it
PaymentCard.on('checkout:paymentResult', function (data) {
// send info to sum.php here
})
</script>
ASKER
Thanks
I get the information shown
Nowall I need to do is send to the sum.php file, so I can process it in PHP
I get the information shown
Nowall I need to do is send to the sum.php file, so I can process it in PHP
so replace :
// send info to sum.php here
by (assuming you've jQuery in the box) :
// send info to sum.php here
by (assuming you've jQuery in the box) :
jQuery.post("/path/to/sum.php", data, function(result) {
alert(result); // alert( JSON.stringify(result) ); if sum.php return JSON data
});
ASKER
great thank you
I can get the results into sum.php - and even get sum.php to send an email
but the javascript remains on the screen and does not let the php display itself or load another page
I can get the results into sum.php - and even get sum.php to send an email
but the javascript remains on the screen and does not let the php display itself or load another page
but the javascript remains on the screen
I believe you mean the html or the page
if you want to redirect to a page, use :
location.href = "/path/to/new/page.php";
jQuery.post("/path/to/sum.php", data, function(result) {
location.href = "/path/to/new/page.php"; // location.reload(); to reload the page
});
ASKER
Thank you again
Can you tell me what is wrong with this
It is not loading the next page (without the if it does!)
Can you tell me what is wrong with this
jQuery.post("sum.php", data, function(result) {
alert(result); // alert( JSON.stringify(result) ); if sum.php return JSON data
if (result.find('FAILED')) {location.href = "../sc.php?mode=9"; } else
{location.href = "../sc.php?mode=82" ;}
It is not loading the next page (without the if it does!)
no, I can't because I don't have your data (result)
my first question in my first answer was : what do you see in the alert?
look like your "result.find('FAILED')" fail
my first question in my first answer was : what do you see in the alert?
look like your "result.find('FAILED')" fail
ASKER
jQuery.post("sum.php", data, function(result) {
// alert(result);
location.href = "../sc.php?mode=" + (result.indexOf('FAILED')>=0)?9:82;
ASKER
Thanks again for all your assistance
Is copied this exactly
It is just trying to load 9 (without the sc.php?mode=)
Is copied this exactly
location.href = "../sc.php?mode=" + (result.indexOf('FAILED')>=0)?9:82;
It is just trying to load 9 (without the sc.php?mode=)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again
That worked !
That worked !
ASKER
Thanks for all the assitance!
'welcome!
another way would be to have a form with hidden fields in your page, you put your data in each fields and you post this form using :
now in sum.php you check, with PHP, if it fail or not and redirect to the rigth page sc.php mode 9 or 82
PaymentCard.on('checkout:paymentResult', function (data) {
$("#hiddenfield1").val( data.someValueWithName1 );
$("#hiddenfield2").val( data.someValueWithName2 );
$("#hiddenfield3").val( data.someValueWithName3 );
$("#formWithHiddenFields").submit();
});
now in sum.php you check, with PHP, if it fail or not and redirect to the rigth page sc.php mode 9 or 82
// send info to sum.php here
by :
alert(data); // or use alert( JSON.stringify(data) );
what do you see in the alert?