欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
  Handling Custom Data Types(处理自定义数据类型)
  
  jQuery的Ajax实现了一套标准的数据类型,比如text, json, xml, 和 html。
  
  在 $.ajaxSetup() 中使用converters选项 来增加或修改数据类型使用$.ajax()转换策略。
  
  未更改的 jQuery 代码 本身包含一个列表的默认转换器,这有力地说明了可以如何使用它们:
  
  // List of data converters
  
  // 1) key format is "source_type destination_type"
  
  //    (a single space in-between)
  
  // 2) the catchall symbol "*" can be used for source_type
  
  converters: {
  
  // Convert anything to text
  
  "* text": window.String,
  
  // Text to html (true = no transformation)
  
  "text html": true,
  
  // Evaluate text as a json expression
  
  "text json": jQuery.parseJSON,
  
  // Parse text as xml
  
  "text xml": jQuery.parseXML
  
  }
  
  当你在$.ajaxSetup()全局的指定一个converters 选项,或者每次调用$.ajax(),这个对象将映射到默认的转换器,覆盖您所指定的那些,让其他不变。
  
  例如,jQuery代码使用$.ajaxSetup()添加一个“text script”转换器:
  
  jQuery.ajaxSetup({
  
  accepts: {
  
  script: "text/javascript, application/javascript"
  
  },
  
  contents: {
  
  script: /javascript/
  
  },
  
  converters: {
  
  "text script": jQuery.globalEval
  
  }
  
  });

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h63938.shtml