How to replace jQuery.ajax() with vanilla JavaScript in WordPress — getButterfly


In an effort to remove all jQuery dependency from one of my plugins, I decided to turn all jQuery.ajax() requests into vanilla JavaScript requests. Turns out it’s pretty simple. Here’s the original request, before: jQuery.ajax({ type: ‘post’, url: ipAjaxVar.ajaxurl, data: ‘action=imagepress-like&nonce=’ + ipAjaxVar.nonce + ‘&imagepress_like=&post_id=’ + pid, success: function (count) { if (count.indexOf(‘already’) !== -1) […]

via How to replace jQuery.ajax() with vanilla JavaScript in WordPress — getButterfly

Advertisements