Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding dataTypes to jQuery.ajax?

Tags:

jquery

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?

like image 432
Justin Alexander Avatar asked Dec 05 '25 19:12

Justin Alexander


1 Answers

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

like image 180
Nick Craver Avatar answered Dec 08 '25 13:12

Nick Craver