【发布时间】:2013-06-16 14:39:03
【问题描述】:
当我将项目拖到购物车区域时,我需要用信息填充我的数组,即使我放了这个函数
var ProductInfo=new Array();
myGlobalArray=GetProductById(iProductId);
调用这个Ajax函数
function GetProductById(iProductId)
{
var ProductInfo=new Array();
console.log("2");
$.ajax({
type: 'POST',
url: 'services/ManageCategoriesServices.asmx/GetProductById',
dataType: 'xml',
'data': {'iProductId': iProductId },
success: function(data) {
source = null;
try
{
console.log("source product-> ",data.activeElement.childNodes);
myGlobalArray=TestProduct(data.activeElement.childNodes);
console.log("In Ajax myGlobalArray-> ",myGlobalArray); return myGlobalArray;
}
catch(e) {
$('#m_lblStatus').text('failed to read json');
}
},
fail: function() { $('#m_lblStatus').text('fail');}
});
return myGlobalArray;
}
我检查了我的 myGlobalArray 是否获得了我需要的完整信息,但是当我尝试复制数组时回到我的第一个函数
myGlobalArray=GetProductById(iProductId);
它是空的,它说
没有子对象
我使用了全局数组,因为通常不会工作,所以我认为全局会工作 但在 ajax 中没有,我看到它已满,但在第一个函数中它是空的。
In Ajax myGlobalArray-> ["medium_101-01-004-02.jpg", "303", "101-01-004-02", "44.95"]
After Ajax myGlobalArray-->[] There are no child objects
问题出在哪里?
【问题讨论】:
标签: javascript asp.net-ajax asp.net-1.1