0

I currently have a standard hyperlink with two query strings to send to a PHP form seen below:

echo ' <strong>(<a id="cancel-upgrade" href="unsubscribe.php?cu='.$payRef.'&su='.$stripe_subscription_id.'">Cancel upgrade)</a></strong>';

The only way I know how to send data via AJAX is:

$.post('process-payment.php', $("form#payment-form").serialize(), function (data) {
    if (data == "success") {
        ...something
    else {
        Something else
    }
});

Is there anyway to use the link I have currently and use the query string data, via AJAX, to the PHP form and act on the success/error messages received?

1
  • 3
    Your question is not clear Commented Jun 26, 2015 at 9:26

3 Answers 3

1

You can add query string parameters to a POST request exactly as you would a GET request. For example:

$.post('process-payment.php?someKey=someValue&anotherKey=anotherValue', //...

So if you're echoing those values from PHP it might look like:

$.post('process-payment.php?cu=<?php echo $payRef; ?>&su=<?php echo $stripe_subscription_id; ?>', //...

(Or any of several ways to emit text to the PHP page.)

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

$.ajax({
        type: "POST",
        url: "ajax_file.php",
        data: 'param1=value1&param2=value2',
        success: function(result){

            }
    });

Comments

0

Use this code:

$(document).ready(function(){

   $( "#cancel-upgrade" ).on( "click", function() {
$.ajax({
        type: "POST",
        url: "unsubscribe.php",
        data: {cu:<?php echo $payRef; ?>, su:<php echo $stripe_subscription_id; ?>},
        success: function(result){

            }
    });
});
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.