Ok, figured it out.
in amplifyjs this section caught my eye
beforeSend : function( _xhr, _ajaxSettings ) {
xhr = _xhr;
ajaxSettings = _ajaxSettings;
var ret = defnSettings.beforeSend ?
defnSettings.beforeSend.call( this, ampXHR, ajaxSettings ) : true;
return ret && amplify.publish( "request.before.ajax",
defnSettings, settings, ajaxSettings, ampXHR );
}
});
note that, it will call beforeSend if it is specified, else set
is set to var ret
true
if set to true, it will then publish "request.before.ajax"
way down in the file, amplify listens for this message
amplify.subscribe( "request.before.ajax", function( resource, settings, ajaxSettings, ampXHR ) {
var _success = ampXHR.success,
_error = ampXHR.error,
decoder = $.isFunction( resource.decoder )
? resource.decoder
: resource.decoder in amplify.request.decoders
? amplify.request.decoders[ resource.decoder ]
: amplify.request.decoders._default;
if ( !decoder ) {
return;
}
function success( data, status ) {
_success( data, status );
}
function error( data, status ) {
_error( data, status );
}
ampXHR.success = function( data, status ) {
decoder( data, status, ampXHR, success, error );
};
ampXHR.error = function( data, status ) {
decoder( data, status, ampXHR, success, error );
};
});
so, if you have a beforeSend and if it does not return true, the message is never published and the decoders are never hit!
the solution?
return true from your beforeSend function
amplify.request.define("testRequest", "ajax", {
url: "/echo/json/",
dataType: 'json',
type: 'POST',
decoder: function(data, status, xhr, success, error) {
console.log('decoder fired');
$('.messages').append('<div>decoder fired </div>');
success(data);
},
beforeSend: function(xhr){
//not doing anything here, just logging;
console.log('before send fired');
$('.messages').append('<div>before send fired </div>');
return true; //this is the key
}
});
works like a charm! Hope this helps someone else trying to figure this out!