我在任何函数之外声明 windows.uris,然后在警告 window.uris 为空时在最后一行添加 $.each() 中的元素。为什么 ?
window.uris = new Array();
window.groups = new Array();
jQuery(document).ready(function($) {
host = document.location.host,
path = document.location.pathname;
url = host + path;
var domg = new Object();
var optgroup;
var productsDom = "";
if (contains(url, 'manage/items.php')) {
$.post('http://localhost/frontaccounting/proxy.php',
{
"url":"http://localhost:8081/stock/categories/",
"m":"get",
"data": ""
},
function (data) {
d = $.parseXML(data);
$xml = $( d );
$xml.find("category").each(
function (i,e) {
optgroup = '<optgroup label="'+ $(e).children("name").text()+'">';
categoryId = $(e).children("id").text();
auxx = (categoryId*1);
window.uris[i]="http://localhost:8081/stock/categories/" + (auxx );
window.groups[auxx + ""] = optgroup;
}
);
}
);
//sleep(2000);
alert('URI' + window.uris);