Ajax Code:
<script>
jQuery(function($) {
$('#payment-form').submit(function(event) {
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('input[type=submit]').attr('disabled', true);
$.ajax({
type: "POST",
url: "https://example.com/ipn.php",
data: { "tid": "123456", "amount": "9.99" },
success: function() { document.location = "https://example.com/success.php" },
});
return false;
});
});
</script>
Script working OK, show my logs:
[Mon May 29 14:47:57 2023][13694] POST data:
'tid' => '123456',
'amount' => '9.99'
But for the script to work properly, I need a JSON version with which the server will call the address itself.
Here is my JSON code
$id = '123456';
$a = '9.99';
$url = 'https://example.com/ipn.php';
$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "tid"=> $id, "amount"=> $a ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
echo "<pre>$result</pre>";
Unfortunately, but in the logs it crashes something that is wrong and shows an error
[Mon May 29 16:17:30 2023][24645] POST data:
'POSTDATA' => '{"tid":"2447655759","amount":"9.99"}'
I would like the server to send a response using JSON. Please help!
I want the script to run in json