October: Second calling ajaxSuccess from jQuery

Created on 20 Apr 2019  路  13Comments  路  Source: octobercms/october

  • OctoberCMS Build: 451
  • PHP Version: 7.3
  • jQuery: 3.3.x - 3.4.0
  • Database Engine: MySQL
  • Plugins Installed: Custom plugins

Description:

Hi! I noticed that the call to the ajaxSuccess event occurs twice:
Once from the framework.js file and the second time from the jQuery library

// OctoberCMS Event
$(document).on('ajaxSuccess', function (event, context, data, status, jqXHR) {
    console.log('event', event);
    console.log('context', context);
    console.log('data', data);
    console.log('status', status);
    console.log('jqXHR', jqXHR);
});

The first time all the parameters matches the framework.js, the second time the parameter data matches the ajaxSuccess from jQuery: http://api.jquery.com/ajaxSuccess/ and I see errors in the console.

How can I disable the event call from the jQuery library?

Completed Bug

All 13 comments

@ayumihamsaki could you chime in on this?

I'm not sure, if it's being called twice, would it be a good idea to remove it from the framework.js and reply on it directly from jquery. I think the jquery file has newer code to process this, than the framework.js - is what I'm saying. I think I read they did some update on to in the 3.4.0 release ? (But don't quote me on that).

Is it possible to see a screenshot of the console.log

Also will ask @w20k what he thinks as well.

@VoroninWD you cannot skip jQuery events. Might be a hack or a trick, how to use only framework.js events, but those are the global jQuery events.

Events:["ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend"]
Let me check our latest version, also.

In the latest version you could disable those, but globally:

  1. Use global: false
$.ajax({
    url: "test.html",
    global: false,
    beforeSend: function(){$.event.trigger('ajaxStart');},
    complete: function(){$.event.trigger('ajaxStop');},
    error: your_error_handler
});
  1. Don't know if it works, but should 馃槃. Disable specific event:
$.event.global.ajaxSuccess

Is it possible to see a screenshot of the console.log

image

@w20k , how can I disable a global event if I send a request like this:

<input
    type="checkbox"
    data-request="bronxShopCatalog::onChangeFilter"
    data-request-data="name: 'colors', value: 'belyy'"
>

@VoroninWD right now the only way is to fix it in the framework.js line:115. So, you have to patch it and recompile assets, if it helps sounds like a PR to me.

@ayumihamsaki did the original version of jQuery included in OctoberCMS (prior to v3) fire those events? If not, I don't see why we can't just disable them entirely by default.

@LukeTowers it was there from the version 1.x something. Probably something else in the core changed, that's more likely.

Yes I've seen jQuery update some things in the core since then. I agree it's best to disable them entirely by default.

Let's have it be disabled by default but give the developer the ability to re-enable it by hooking into an appropriate event and setting the option

@LukeTowers, I disabled events by default. Documentation is ready. What else is needed?

It's potentially a breaking change so it'll go in the next build when the current builds go stable

Was this page helpful?
0 / 5 - 0 ratings