Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bindSweetAlertButtonDemo() {
- const swalButton = document.querySelectorAll('.sweet-alert-demo');
- swalButton.forEach((dom) => {
- let form = $(dom).closest('form')
- console.log('HELLO FROM FORM');
- console.log(form);
- let cryptocurrency_id = window.location.search.split("?crypto_id=")[1]
- console.log('HELLO FROM CRYPTOCURRENCY ID');
- console.log(cryptocurrency_id);
- let url = `/cryptocurrencies/${cryptocurrency_id}/trades`;
- console.log('HELLO FROM URL');
- console.log(url);
- // url = /cryptocurrencies/3/trades
- form.on('submit', (e) => {
- e.preventDefault()
- e.stopPropagation()
- swal({
- title: "Are you sure?",
- text: "Is this the cryptocurrency you wanna buy?",
- icon: "warning",
- buttons: true,
- dangerMode: true,
- }).then((willSave) => {
- if (willSave) {
- $.ajax({
- headers: {
- 'X-CSRF-Token': $(form).find('[name="authenticity_token"]').val()
- },
- url: `${url}.json`,
- type: "POST"
- }).done(function() {
- swal("Booking canceled!", {
- icon: "success",
- }).then(() => {
- location.reload()
- });
- })
- }
- });
- })
- })
- };
Add Comment
Please, Sign In to add comment