| 1006 | * Also sets the responseXXX fields on the jqXHR instance |
| 1007 | */ |
| 1008 | function ajaxConvert(s, response, jqXHR, isSuccess) { |
| 1009 | var conv2, current, conv, tmp, prev, |
| 1010 | converters = {}, |
| 1011 | // Work with a copy of dataTypes in case we need to modify it for conversion |
| 1012 | // 使用数据类型的副本,以防我们需要修改转换 |
| 1013 | dataTypes = s.dataTypes.slice(); |
| 1014 | |
| 1015 | // Create converters map with lowercased keys |
| 1016 | // 用小写的键创建转换器map |
| 1017 | // 将s.converters复制到converters |
| 1018 | if (dataTypes[1]) { |
| 1019 | for (conv in s.converters) { |
| 1020 | converters[conv.toLowerCase()] = s.converters[conv]; |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | current = dataTypes.shift(); |
| 1025 | |
| 1026 | // Convert to each sequential dataType |
| 1027 | while (current) { |
| 1028 | |
| 1029 | //替换真实的值 |
| 1030 | //jqXHR.responseText: "{"a":1,"b":2,"c":3,"d":4,"e":5}" |
| 1031 | if (s.responseFields[current]) { |
| 1032 | jqXHR[s.responseFields[current]] = response; |
| 1033 | } |
| 1034 | |
| 1035 | // Apply the dataFilter if provided |
| 1036 | if (!prev && isSuccess && s.dataFilter) { |
| 1037 | response = s.dataFilter(response, s.dataType); |
| 1038 | } |
| 1039 | |
| 1040 | prev = current; |
| 1041 | current = dataTypes.shift(); |
| 1042 | |
| 1043 | if (current) { |
| 1044 | |
| 1045 | // There's only work to do if current dataType is non-auto |
| 1046 | // 如果碰到了*号,即一个任意类型,而转换为任意类型*没有意义 |
| 1047 | if (current === "*") { |
| 1048 | |
| 1049 | current = prev; |
| 1050 | |
| 1051 | // Convert response if prev dataType is non-auto and differs from current |
| 1052 | // 转化的重点 |
| 1053 | // 如果不是任意的类型,并且找到了一个不同的类型 |
| 1054 | } else if (prev !== "*" && prev !== current) { |
| 1055 | |
| 1056 | // Seek a direct converter |
| 1057 | // 组成映射格式,匹配转化器 |
| 1058 | // * text: function String() { [native code] } |
| 1059 | // script json: function () { |
| 1060 | // text html: true |
| 1061 | // text json: function parse() { [native code] } |
| 1062 | // text script: function (text) { |
| 1063 | // text xml: function (data) { |
| 1064 | // |
| 1065 | conv = converters[prev + " " + current] || converters["* " + current]; |