Link to home
Start Free TrialLog in
Avatar of Paul Southcott
Paul SouthcottFlag for Guernsey

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 ??

<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>

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

replace :
// send info to sum.php here
by :
alert(data); // or use alert(  JSON.stringify(data)  );

what do you see in the alert?
Avatar of Paul Southcott

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
so replace :
// 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
});

Open in new window

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
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
});

Open in new window

Thank you again

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" ;}

Open in new window


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
Here is screen shot of the result

Thanks again
2019-04-09.png
jQuery.post("sum.php", data, function(result) {
	// alert(result);
	location.href = "../sc.php?mode=" + (result.indexOf('FAILED')>=0)?9:82;

Open in new window

Thanks again for all your assistance

Is copied this exactly
 
location.href = "../sc.php?mode=" + (result.indexOf('FAILED')>=0)?9:82;

Open in new window


It is just trying to load 9 (without  the sc.php?mode=)
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again

That worked !
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 :

                PaymentCard.on('checkout:paymentResult', function (data) {
                           $("#hiddenfield1").val( data.someValueWithName1 );
                           $("#hiddenfield2").val( data.someValueWithName2 );
                           $("#hiddenfield3").val( data.someValueWithName3 );
                           $("#formWithHiddenFields").submit();
                 });

Open in new window


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