how does jquery guess the better datatype in Ajax method?

后端 未结 2 1849
栀梦
栀梦 2021-01-18 03:55

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

2条回答
  •  不要未来只要你来
    2021-01-18 04:34

    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

提交回复
热议问题