it is wriiten in jquery document about Ajax method and its dataType:
\' Default: Intelligent Guess \'
how does jquery guess the better datatype for this meth
Don't rely on jQuery to correctly guess your returned dataType
. I was returning text
but I was foolishly assuming that text
was the default setting without looking at the documentation and my ajax requests would seemingly randomly fail, giving some of my users a bad experience and others would be fine.
i.e. jQuery cannot reliably intelligently guess text
as a dataType
.
Primarily by looking at the Content-Type header of the response. Details in the ajaxHandleResponses
function in the source (currently, for v1.5.2, starting at line 6,932).
From the documentation:
dataType
: ... If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string).
Re
if the output of requested url via ajax has html and script both,which one will be consider? html or script as dataType?
That would be HTML with embedded script tags, which are also HTML. The script
tags will be evaluated when (if) you insert the HTML into the DOM. Example: http://jsbin.com/utuha3