Pregunta

We're trying to upgrade our jquery using jquery migrate.

We get the "JQMIGRATE: Global events are undocumented and deprecated" on this code (a wrapper for jquery.ajax):

ajaxPost: function (url, jsonData, successCallback, async) {
        if (async == null) {
            async = true;
        }

        var ajaxSettings = {
            url: url,
            type: 'POST',
            async: async,
            data: JSON.stringify(jsonData),
            contentType: 'application/json; charset=UTF-8',
            success: function (data, code, xht) {
                successCallback(data, code, xht);
            },
            error: function (xht, errorType, exception) {
               console.log(...);
            }
        };

        $.ajax(ajaxSettings);
}

The "error" occurs for this line:

 successCallback(data, code, xht);

We're not sure how to fix it?!

¿Fue útil?

Solución

This is a piece of code from JQMIGRATE responsible for warning

// Turn global events into document-triggered events
jQuery.event.trigger = function( event, data, elem, onlyHandlers  ){
    if ( !elem && !rajaxEvent.test( event ) ) {
        migrateWarn( "Global events are undocumented and deprecated" );
    }
    return eventTrigger.call( this,  event, data, elem || document, onlyHandlers  );
};

Looks like this warning is popping on trigger() calls in two cases:

1) no element is specified as trigger context

2) event is global ajax event

Global ajax event example:

  $(document).bind("ajaxSend", function(){
   $("#loading").show();
 }).bind("ajaxComplete", function(){
   $("#loading").hide();
 });

But if you say you had disabled global events by setting jQuery.ajaxSetup({global: false}), then problem could be caused by case 1, but i dont see any code releavant to it in the provided fragment.

Probably you need to check implementation of method successCallback for case 1.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top