当前位置: 动力学知识库 > 问答 > 编程问答 >

Javascript global array turns to undefined for no reason

问题描述:

In my web pages I have 2 lists of items which are loaded from DB. To decrease traffic I store all items loaded from DB in global array and when the user searches the list, I search the array first and only when the item is not found I go to the DB.

So at first I define my global array at the top of my script and only once.

var _navArr=[];

And then I want to access it with this code

$.ajax({ //At breakpoint here the _navArr is defined and full of items

type: "POST",

url: "Webservices/ws_publikace.svc/ws_getUserNavigatorList",

data: data,

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function (msg) {

//But inside success function _navArr is undefined

_navArr[navArr] = extedItemArr(_navArr[navArr], msg.d);

}

});

But it doesn't work as described in the code.

Any Idea why is it so? Thanks

网友答案:

Instead var _navArr=[]; try window._navArr = [];

分享给朋友:
您可能感兴趣的文章:
随机阅读: