#cross-domain #extjs4 #cross-domain-policy
#междоменная #extjs4 #междоменная политика
Вопрос:
У меня есть простая модель:
Ext.define('MovieModel', {
extend : 'Ext.data.Model',
fields : [ {
name : 'Title',
mapping : '@title',
type : 'string'
} ],
proxy : {
type : 'ajax',
url : 'http://www.imdbapi.com/?r=xmlamp;plot=full',
method : 'GET',
reader : {
type : 'xml',
record : 'movie'
}
}
});
Но этот код не поддерживает междоменную политику. Как я мог это решить?
Ответ №1:
Прежде всего избавьтесь от r=xml
param . Вместо ajax
прокси используйте jsonp
один:
proxy : {
type : 'jsonp',
url : 'http://www.imdbapi.com/?plot=full',
// jsonp uses its special method for retrieving data. So no need for the following row
//method : 'GET',
reader : {
type : 'json',
// the record param is used when data is nested construction
// which is not true in your case
//record : 'movie'
}
}
Вот демонстрация.
Комментарии:
1. @bontade, правильно.
callback=callback
не требуется. Обновил мой ответ (ознакомьтесь с демонстрацией ).