1
我的應用程序文件夾下有3個文件 - Index.html,Main.js和state.json。以下JavaScript代碼來自Main.js.從state.json獲取數據的正確url格式是什麼?dojo.xhr從具有相對路徑的文件中獲取數據
顯然網址:'/state.json'沒有工作。
dojo.xhrGet({
url: '/state.json',
handleAs: json,
load: function (result) {
require([
'dojo/store/Memory',
"dijit/form/FilteringSelect",
'dojo/domReady!'
], function (Memory, FilteringSelect) {
var stateStore = new Memory({
idProperty: 'code',
data: result.states.sort(function(a,b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return x < y ? -1 : x > y ? 1 : 0;
})
});
var cboState = new FilteringSelect({
id: 'usastate',
name: 'usastate',
style:{width: '100%', height: '35px', fontSize: '30px'},
placeholder: 'Select a State',
store: stateStore,
searchAttr: 'name',
autocomplete: true,
onChange: function(value) {
dom.byId('statecode').innerHTML = value;
}
});
cboState.placeAt(dom.byId('state')).startup();
});
}
});
直接使用'網址: 'state.json',' –