eranga Posted June 2, 2020 Share Posted June 2, 2020 (edited) I would like to calculate number of trees to be planted per transaction and POST to https://offset.earth/ API. Would also like to show to customers in the order confirmation how many trees they planted for this transaction. would anyone know how to achieve this in squarespace? Thanks in advance Edited June 7, 2020 by eranga Link to comment
eranga Posted June 7, 2020 Author Share Posted June 7, 2020 <script> var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { alert(this.responseText); } }; xhttp.open("POST", "TARGET URL", true); xhttp.setRequestHeader("Content-Type", "application/json"); xhttp.setRequestHeader("Authorization", "AUTHORISATION ID); var num = 1; //send a random number xhttp.send('{"number": ' + num + '},{"test": true}'); </script> I managed to figure this out with help. Hope this will help someone. I injected the above code to order confirmation. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment