3

jQuery.ajax({dataType:...}) supports several known dataTypes (xml, json,jsonp, script,text, or html).

Is there a way to add your own datatype handlers like:

var wcf = function(data){...}

jQuery.ajax({dataType:wcf, ...});

Obviously I've already tried this, and it doesn't work. But is there another way?

1

2 Answers 2

1

There isn't really a clean way to do this, at least not as far as jQuery 1.4.4 simply because there are tons of if() checks inside $.ajax() that rely on datatypes, and that's how they're currently "supported". However, jQuery 1.4.5 will have some interesting changes here.

If you're curious, you can browse github for the latest and see how jQuery AJAX behavior is being made much more extensible by dividing the transport code: https://github.com/jquery/jquery/tree/master/src/transports

Sign up to request clarification or add additional context in comments.

Comments

1

You can create your own implementation of jQuery.ajax function, like:

(function($) {
    var ajax = $.ajax;
    $.ajax = function(o) {
        // perform some custom logic here...
        var result = ajax.apply(this, arguments);
        // ...and here
        return result;
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.