Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom ajaxTransport function without specified dataType is not firing (AT ALL!)

I have been trying to setup custom ajaxTransports for jQuery to short-circuit some workflows in certain scenarios for our product. However, I have had zero success in getting these transports to be honored (whereas I have many working custom ajaxPrefilters).

Tested with multiple versions of jQuery:

  • 1.5.2
  • 1.6.4
  • 1.7.2
  • 1.8.0

Tested with multiple browsers:

  • Firefox 15
  • Chrome 21
  • iOS 5 webviews

...

None of them worked.

JsFiddle test case: http://jsfiddle.net/PVYut/

...

If I add a dataType to narrow it down, then it works fine.

JsFiddle test case: http://jsfiddle.net/PVYut/1/

...

Am I just doing something all wrong? I'd be happy to be told so, so long as I can get this working! -_-

like image 525
James M. Greene Avatar asked Sep 18 '12 16:09

James M. Greene


1 Answers

$.ajaxTransport("+*", function(options, originalOptions, jqXHR, headers, completeCallback   ) {
    console.log("Executing ajaxTransport");
    return {
        send: function( headers, completeCallback ) {
            completeCallback(404, "error", {});
        },
        abort: function() {
          /* abort code */
        }
    }
});

$.ajax("?jqTrans=" + (+(new Date())))
    .done(function() {
        console.log("ERROR: Should not have been successful!");
    })
    .fail(function() {
        console.log("SUCCESS: Should have failed.");  
    });

Here is jsFiddle

like image 197
Viktor S. Avatar answered Oct 04 '22 23:10

Viktor S.