Page 78 - jQuery для начинающих
P. 78

// 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():


                    $.ajaxSetup({

                           converters: {
                                  "text mydatatype": function( textValue ) {

                                         if ( valid( textValue ) ) {
                                                 // разбор пришедших данных
                                                 return mydatatypeValue;

                                         } else {
                                                 // возникла ошибка
                                                 throw exceptionObject;

                                         }
                                  }
                           }

                    });

                    Имена dataType должны всегда быть в нижнем регистре


             Конверторы  следует  использовать,  если  требуется  внедрить  произвольные  форматы
             dataType,  или  для  конвертации  данных  в  нужный  формат.  Необходимый  dataType
             указываем при вызове метода $.ajax():


                    $.ajax( url, { dataType: "mydatatype" });






                                                                                                         78


                                                                                        www.trk.kg
   73   74   75   76   77   78   79   80   81   82   83