I posted on this and submitted on the ticket tracker to do this but it seems to have been denied (it was abandoned). There was a suggestion made to use the dataFilter but that misses the point since the xhr header doesn't get included as a parameter. To work around this I have a little patch I add just after my jquery include. You can see it here : http://devlicio.us/blogs/mike_nichols/archive/2008/10/14/enabling-auto-detection-of-response-type-in-jquery.aspx
On Apr 10, 3:39 pm, Snef <sne...@gmail.com> wrote: > Well, is it a good suggestion? > > Or maybe it's possible to override (or extends) tjhe current ajax > implementation? > > On 10 apr, 16:45, Snef <sne...@gmail.com> wrote: > > > Hi, > > > When using the $.ajax functionality i came across some things. > > > You have to set the dataType option in order to get the correct data > > at success(). Now I have an ajax request that can return some html or > > json. Both use the correct content-type header. > > > Now I see in the httpData function of jQuery that it will get xml and > > in other occasions it will use the set dataType. Why not a check on > > content-type? > > > In the httpData is a part like: > > > // The filter can actually parse the response > > if( typeof data === "string" ){ > > // If the type is "script", eval it in global > > context > > if ( type == "script" ) > > jQuery.globalEval( data ); > > > // Get the JavaScript object, if JSON is used. > > if ( type == "json" ) > > data = window["eval"]("(" + data + ")"); > > } > > > Maybe it is possible to change it to: > > > // The filter can actually parse the response > > if( typeof data === "string" ){ > > // If the type is "script", eval it in global > > context > > if ( type == "script" || ( !type && > > ct.indexOf("javascript") >= > > 0 ) ) > > jQuery.globalEval( data ); > > > // Get the JavaScript object, if JSON is used. > > if ( type == "json" || ( !type && > > ct.indexOf("json") >= 0 ) ) > > data = window["eval"]("(" + data + ")"); > > } > > > (please check the httpData in jquery.1.3.2.js!) > > > In this way, when dataType is omitted, it'll take a look at the > > returned content type. > > > Offcourse, this is just a quick rewrite and maybe not even correct but > > with some simple tests it worked well. > > > Snef