• Resolved ch264

    (@ch264)


    Hi,
    We are on WordPress 5.5.3 and we have a jQuery 3 cdn.
    The plugin shows the like button successfully but on click I get the following error message:

    wp-ulike.min.js?ver=4.4.2.1:1 Uncaught TypeError: n.ajax is not a function
        at s._ajax (wp-ulike.min.js?ver=4.4.2.1:1)
        at s._initLike (wp-ulike.min.js?ver=4.4.2.1:1)
        at HTMLButtonElement.dispatch (jquery-3.2.1.slim.min.js?ver=5.5.3:3)
        at HTMLButtonElement.q.handle (jquery-3.2.1.slim.min.js?ver=5.5.3:3)

    I tried installing the jQuery Migrate Helper but it the same error message keeps coming up when clicking on the button. We removed the plugin from the live site for now but I would like to get this working.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Alimir

    (@alimir)

    Hi @ch264
    This problem is probably due to the uglify js task we use in the grunt file. We will fix this issue for the next update.
    Until then, you can change the contents of the wp-ulike.min.js file to the following code:

    !function(t,e,i,s){"use strict";var n={messageType:"success",messageText:"Hello World!",timeout:8e3,messageElement:"wpulike-message",notifContainer:"wpulike-notification"};function l(e,i){this.element=e,this.$element=t(e),this.settings=t.extend({},n,i),this._defaults=n,this._name="WordpressUlikeNotifications",this.init()}t.extend(l.prototype,{init:function(){this._message(),this._container(),this._append(),this._remove()},_message:function(){this.$messageElement=t("<div/>").addClass(this.settings.messageElement+" wpulike-"+this.settings.messageType).text(this.settings.messageText)},_container:function(){t("."+this.settings.notifContainer).length||this.$element.append(t("<div/>").addClass(this.settings.notifContainer)),this.$notifContainer=this.$element.find("."+this.settings.notifContainer)},_append:function(){this.$notifContainer.append(this.$messageElement).trigger("WordpressUlikeNotificationAppend")},_remove:function(){var e=this;this.$messageElement.click((function(){t(this).fadeOut(300,(function(){t(this).remove(),t("."+e.settings.messageElement).length||e.$notifContainer.remove()})).trigger("WordpressUlikeRemoveNotification")})),e.settings.timeout&&setTimeout((function(){e.$messageElement.fadeOut(300,(function(){t(this).remove(),t("."+e.settings.messageElement).length||e.$notifContainer.remove()})).trigger("WordpressUlikeRemoveNotification")}),e.settings.timeout)}}),t.fn.WordpressUlikeNotifications=function(t){return this.each((function(){new l(this,t)}))}}(jQuery,window,document),function(t,e,i,s){"use strict";t(e);var n=t(i),l={ID:0,nonce:0,type:"",append:"",appendTimeout:2e3,displayLikers:!1,disablePophover:!0,isTotal:!1,factor:"",template:"",counterSelector:".count-box",generalSelector:".wp_ulike_general_class",buttonSelector:".wp_ulike_btn",likersSelector:".wp_ulike_likers_wrapper"},a={"ulike-id":"ID","ulike-nonce":"nonce","ulike-type":"type","ulike-append":"append","ulike-is-total":"isTotal","ulike-display-likers":"displayLikers","ulike-disable-pophover":"disablePophover","ulike-append-timeout":"appendTimeout","ulike-factor":"factor","ulike-template":"template"};function o(e,i){for(var s in this.element=e,this.$element=t(e),this.settings=t.extend({},l,i),this._defaults=l,this._name="WordpressUlike",this.buttonElement=this.$element.find(this.settings.buttonSelector),this.generalElement=this.$element.find(this.settings.generalSelector),this.counterElement=this.generalElement.find(this.settings.counterSelector),this.likersElement=this.$element.find(this.settings.likersSelector),a){var n=this.buttonElement.data(s);void 0!==n&&(this.settings[a[s]]=n)}this.init()}t.extend(o.prototype,{init:function(){this.buttonElement.click(this._initLike.bind(this)),this.generalElement.one("mouseenter",this._updateLikers.bind(this))},_ajax:function(e,i){t.ajax({url:wp_ulike_params.ajax_url,type:"POST",cache:!1,dataType:"json",data:e}).done(i)},_initLike:function(t){t.stopPropagation(),this._maybeUpdateElements(t),this._updateSameButtons(),this._updateSameLikers(),this.buttonElement.prop("disabled",!0),n.trigger("WordpressUlikeLoading",this.element),this.generalElement.addClass("wp_ulike_is_loading"),this._ajax({action:"wp_ulike_process",id:this.settings.ID,nonce:this.settings.nonce,factor:this.settings.factor,type:this.settings.type,template:this.settings.template,displayLikers:this.settings.displayLikers,disablePophover:this.settings.disablePophover},function(t){this.generalElement.removeClass("wp_ulike_is_loading"),t.success?(this._updateMarkup(t),this._appendChild()):this._sendNotification("error",t.data),this.buttonElement.prop("disabled",!1),n.trigger("WordpressUlikeUpdated",this.element)}.bind(this))},_maybeUpdateElements:function(e){this.buttonElement=t(e.currentTarget),this.generalElement=this.buttonElement.closest(this.settings.generalSelector),this.counterElement=this.generalElement.find(this.settings.counterSelector),this.settings.factor=this.buttonElement.data("ulike-factor")},_appendChild:function(){if(""!==this.settings.append){var e=t(this.settings.append);this.buttonElement.append(e),this.settings.appendTimeout&&setTimeout((function(){e.detach()}),this.settings.appendTimeout)}},_updateMarkup:function(t){this._setSbilingElement(),this._setSbilingButtons(),this._updateGeneralClassNames(t.data.status),null!==t.data.data&&(t.data.status<5&&(this.__updateCounter(t.data.data),this.settings.displayLikers&&void 0!==t.data.likers&&this._updateLikersMarkup(t.data.likers)),this._updateButton(t.data.btnText,t.data.status)),this._sendNotification(t.data.messageType,t.data.message)},_updateGeneralClassNames:function(t){var e="wp_ulike_is_not_liked",i="wp_ulike_is_liked",s="wp_ulike_is_unliked",n="wp_ulike_click_is_disabled";switch(this.siblingElement.length&&this.siblingElement.removeClass(this._arrayToString([i,s])),t){case 1:this.generalElement.addClass(i).removeClass(e),this.generalElement.children().first().addClass(n);break;case 2:this.generalElement.addClass(s).removeClass(i);break;case 3:this.generalElement.addClass(i).removeClass(s);break;default:this.generalElement.addClass(n),this.siblingElement.length&&this.siblingElement.addClass(n)}},_arrayToString:function(t){return t.join(" ")},_setSbilingElement:function(){this.siblingElement=this.generalElement.siblings()},_setSbilingButtons:function(){this.siblingButton=this.buttonElement.siblings(this.settings.buttonSelector)},__updateCounter:function(t){"object"!=typeof t?this.counterElement.text(t):this.settings.isTotal&&void 0!==t.sub?this.counterElement.text(t.sub):"down"===this.settings.factor?(this.counterElement.text(t.down),this.siblingElement.length&&this.siblingElement.find(this.settings.counterSelector).text(t.up)):(this.counterElement.text(t.up),this.siblingElement.length&&this.siblingElement.find(this.settings.counterSelector).text(t.down)),n.trigger("WordpressUlikeCounterUpdated",[this.buttonElement])},_updateLikers:function(){this.settings.displayLikers&&!this.likersElement.length&&(this.generalElement.addClass("wp_ulike_is_getting_likers_list"),this._ajax({action:"wp_ulike_get_likers",id:this.settings.ID,nonce:this.settings.nonce,type:this.settings.type,displayLikers:this.settings.displayLikers,disablePophover:this.settings.disablePophover},function(t){this.generalElement.removeClass("wp_ulike_is_getting_likers_list"),t.success&&this._updateLikersMarkup(t.data)}.bind(this)))},_updateLikersMarkup:function(e){this.likersElement.length||(this.likersElement=t("<div>",{class:e.class}).appendTo(this.$element)),e.template?this.likersElement.show().html(e.template):this.likersElement.hide()},_updateSameButtons:function(){var t=void 0!==this.settings.factor?"_"+this.settings.factor:"";this.sameButtons=n.find(".wp_"+this.settings.type.toLowerCase()+t+"_btn_"+this.settings.ID),this.sameButtons.length>1&&(this.buttonElement=this.sameButtons,this.generalElement=this.buttonElement.closest(this.settings.generalSelector),this.counterElement=this.generalElement.find(this.settings.counterSelector))},_updateSameLikers:function(){this.sameLikers=n.find(".wp_"+this.settings.type.toLowerCase()+"_likers_"+this.settings.ID),this.sameLikers.length>1&&(this.likersElement=this.sameLikers)},_getLikersElement:function(){return this.likersElement},_updateButton:function(t,e){this.buttonElement.hasClass("wp_ulike_put_image")?(this.buttonElement.toggleClass("image-unlike wp_ulike_btn_is_active"),this.siblingElement.length&&this.siblingElement.find(this.settings.buttonSelector).removeClass("image-unlike wp_ulike_btn_is_active"),this.siblingButton.length&&this.siblingButton.removeClass("image-unlike wp_ulike_btn_is_active")):this.buttonElement.hasClass("wp_ulike_put_text")&&null!==t&&("object"!=typeof t?this.buttonElement.find("span").html(t):"down"===this.settings.factor?(this.buttonElement.find("span").html(t.down),this.siblingElement.length&&this.siblingElement.find(this.settings.buttonSelector).find("span").html(t.up)):(this.buttonElement.find("span").html(t.up),this.siblingElement.length&&this.siblingElement.find(this.settings.buttonSelector).find("span").html(t.down)))},_sendNotification:function(e,s){"1"===wp_ulike_params.notifications&&t(i.body).WordpressUlikeNotifications({messageType:e,messageText:s})}}),t.fn.WordpressUlike=function(e){return this.each((function(){t.data(this,"plugin_WordpressUlike")||t.data(this,"plugin_WordpressUlike",new o(this,e))}))}}(jQuery,window,document),function(t){t((function(){t(this).bind("DOMNodeInserted",(function(e){t(".wpulike").WordpressUlike()}))})),t(".wpulike").WordpressUlike()}(jQuery);

    Thread Starter ch264

    (@ch264)

    Hi @alimir,

    Thanks so much for your fast reply. I exchanged the code and the error message sais now:

    wp-ulike.min.js?ver=4.4.2.1:1 Uncaught TypeError: t.ajax is not a function
        at o._ajax (wp-ulike.min.js?ver=4.4.2.1:1)
        at o._initLike (wp-ulike.min.js?ver=4.4.2.1:1)
        at HTMLButtonElement.dispatch (jquery-3.2.1.slim.min.js?ver=5.5.3:3)
        at HTMLButtonElement.q.handle (jquery-3.2.1.slim.min.js?ver=5.5.3:3)

    Do you have an idea on when the next update will be released?

    Plugin Author Alimir

    (@alimir)

    @ch264 you’re welcome.
    There seems to be a problem with your JQuery! What version of Jquery are you using? Does it support the $.ajax function ?!
    Also, If you also have an online link, please comment it as well.

    Plugin Author Alimir

    (@alimir)

    @ch264 Has the problem been resolved?

    Thread Starter ch264

    (@ch264)

    Hi @alimir, We are using jQuery 3 and the plugin does not work with that. It does work with an older version of jQuery. I believe WordPress is planning on updating the jQuery by March 2021?

    We have discussed that we do not want to downgrade jQuery due to the changes coming to the core. Do you have any plans on making the plugin compatible with jQuery 3?

    Thanks again so much for your help.

    Plugin Author Alimir

    (@alimir)

    Hi @ch264
    We have used completely standard methods in the structure of our jquery plugin. I checked up to Jquery 3.5.1 but there was no problem!
    https://code.jquery.com/jquery-3.5.1.min.js

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘TypeError: n.ajax is not a function’ is closed to new replies.