[jQuery] jQuery $.ajax and dataType

[jQuery] jQuery $.ajax and dataType


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