MCPcopy Create free account
hub / github.com/JsAaron/jQuery / ajaxHandleResponses

Function ajaxHandleResponses

2.0.3/Ajax.js:939–1003  ·  view source on GitHub ↗
(s, jqXHR, responses)

Source from the content-addressed store, hash-verified

937 */
938
939function ajaxHandleResponses(s, jqXHR, responses) {
940
941 var ct, type, finalDataType, firstDataType,
942 contents = s.contents,
943 dataTypes = s.dataTypes;
944
945 // Remove auto dataType and get content-type in the process
946 // 删除掉通配dataType,得到返回的Content-Type
947 while (dataTypes[0] === "*") {
948 dataTypes.shift();
949 if (ct === undefined) {
950 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
951 }
952 }
953
954 // Check if we're dealing with a known content-type
955 // 看看是不是我们能处理的Content-Type,比如图片这类二进制类型就不好处理了
956 if (ct) {
957 // 实际上能处理的就是text、xml和json
958 for (type in contents) {
959 if (contents[type] && contents[type].test(ct)) {
960 dataTypes.unshift(type);
961 break;
962 }
963 }
964 }
965
966 // Check to see if we have a response for the expected dataType
967 // 如果dataTypes是我们想要的,也就是text、xml、json
968 if (dataTypes[0] in responses) {
969 finalDataType = dataTypes[0];
970 } else {
971 // Try convertible dataTypes
972 // 尝试转换成我们要的dataType
973 for (type in responses) {
974 // 如果dataTypes[ 0 ]不存在,则直接用type作为最终dataType
975 // 否则,看看能不能转换,能的话就用type作为最终dataType
976 if (!dataTypes[0] || s.converters[type + " " + dataTypes[0]]) {
977 finalDataType = type;
978 break;
979 }
980 // 保存第一个type
981 if (!firstDataType) {
982 firstDataType = type;
983 }
984 }
985 // Or just use first one
986 // 用最终dataType或者用第一个type
987 finalDataType = finalDataType || firstDataType;
988 }
989
990 // If we found a dataType
991 // We add the dataType to the list if needed
992 // and return the corresponding response
993 // 如果有最终dataType
994 if (finalDataType) {
995 //如果最终dataType不是dataTypes[ 0 ]
996 if (finalDataType !== dataTypes[0]) {

Callers 1

doneFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected