My issue is I need to POST XML data to a payment gateway.
I've tried to follow the answer from PHP Redirect with POST data, but I need to intercept the submit to manipulate the data.
So, I've tried the following:
<html>
<form id="myForm" action="<?php echo $url; ?>" method="post">
</form>
<script type="text/javascript">
$(document).ready (function () {
document.getElementById('myForm').submit();
$('#myForm').submit(function (e) {
console.log('A');
e.preventDefault();
alert("a");
$.post("<?php echo $url; ?>", {'data': formxml}, function (data) {
// callback logic
});
});
});
</script>
</html>
However, it doesn't work as I expected it to be.
When I do the document.getElementById('myForm').submit()
, I expected the $('#myForm').submit
will intercept it and I can do data validation.
How should I proceed with it in order to achieve my expected result?