| 1 |
jQuery(function($){ |
| 2 |
if(window.location.protocol == 'https:'){ |
| 3 |
ajaxurl = ajaxurl.replace('http://', 'https://'); |
| 4 |
} |
| 5 |
|
| 6 |
$.fn.extend({ |
| 7 |
wpjam_submit: function(callback){ |
| 8 |
let _this = $(this); |
| 9 |
let data = new FormData(_this[0]); |
| 10 |
|
| 11 |
data.set('_ajax_nonce', $(this).data('nonce')); |
| 12 |
data.set('action', $(this).data('action')); |
| 13 |
data.set('defaults', $(this).data('data')); |
| 14 |
data.set('data', $(this).serialize()); |
| 15 |
|
| 16 |
$.ajax({ |
| 17 |
type: 'POST', |
| 18 |
url: ajaxurl, |
| 19 |
data: data, |
| 20 |
processData: false, |
| 21 |
contentType: false, |
| 22 |
success: function(data){ |
| 23 |
callback.call(_this, data); |
| 24 |
} |
| 25 |
}); |
| 26 |
}, |
| 27 |
wpjam_action: function(callback){ |
| 28 |
let _this = $(this); |
| 29 |
|
| 30 |
$.post(ajaxurl, { |
| 31 |
_ajax_nonce: $(this).data('nonce'), |
| 32 |
action: $(this).data('action'), |
| 33 |
data: $(this).data('data') |
| 34 |
},function(data, status){ |
| 35 |
callback.call(_this, data); |
| 36 |
}); |
| 37 |
} |
| 38 |
}); |
| 39 |
}); |