jQuery如何猜测Ajax方法中更好的数据类型? [英] how does jquery guess the better datatype in Ajax method?

查看:101
本文介绍了jQuery如何猜测Ajax方法中更好的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它在关于Ajax方法及其dataType的jquery文档中被修改:

it is wriiten in jquery document about Ajax method and its dataType:

'默认:智能猜想'

如果没有为此选择,jQuery如何猜测此方法的更好数据类型?

how does jquery guess the better datatype for this method if nothing is selected for it?

如果通过ajax请求的URL输出同时具有html和script,那么将考虑哪一个? html或脚本作为dataType?

if the output of requested url via ajax has html and script both,which one will be consider? html or script as dataType?

推荐答案

主要通过查看源文件中的ajaxHandleResponses函数的详细信息(当前适用于v1.5.2) ,从6,932行开始).

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).

来自文档:

dataType :... ...如果未指定,则jQuery将尝试根据响应的MIME类型来推断它(XML MIME类型将生成XML,在1.4中,JSON将生成一个JavaScript对象,在1.4脚本中将执行该脚本,其他所有内容都将以字符串形式返回.)

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).

重新

如果通过ajax请求的url输出同时具有html和script,那么将考虑哪一个? html或脚本作为dataType?

if the output of requested url via ajax has html and script both,which one will be consider? html or script as dataType?

那将是带有嵌入式脚本标签的HTML,这也是HTML.当(如果)将HTML插入DOM时,将评估script标记.示例: http://jsbin.com/utuha3

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

这篇关于jQuery如何猜测Ajax方法中更好的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆