On ‘success’ I need to submit data to PayPal. I know that $.post('https://www.paypal.com/cgi-bin/webscr', data); is wrong because I need it to submit as if that were the form action, going to the PayPal page with the form values. All of the data is stored and properly formatted in the return JSON data. I checked it with alert(data.cmd). I just don’t know how to emulate an HTML POST action from here.
function process(plan_id) {
var data = {'plan_id' : plan_id};
$.ajax({
type: "POST",
url: "process_paypal.php",
data: data,
dataType: "json",
success: function (data) {
alert(data.cmd);
$.post('https://www.paypal.com/cgi-bin/webscr', data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(arguments);
alert(jqXHR + '-' + textStatus + '-' + errorThrown);
return false;
}
});
}
</script>
You will need to serialize your data using $.serialize() before sending it onto PayPal like this:
By serializing the data you are converting it from an object to an encoded string which the PayPal service can read.
I hope this helps!