我想訪問陣列arrcolumn[]
我宣佈爲全球array.I正在初始化值陣列arrcolumn[]
在OnSuccess1()
功能。我想在初始化後OnSuccess()
功能使用arrcolumn[]
值OnSuccess1()。 但是arrcolumn[]
在OnSuccess()
函數中爲空。數組是空的,我想訪問數組arrcolumn []
var arrname = [];
var arrmark = [];
var arrcolumn = [];
var arr = [];
var arr1 = [];
//display function
function display() {
$.ajax({
type: "POST",
url: "Default.aspx/fetchStudent",
data: '{}',
contentType: "application/json;charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnErrorCall
});
$.ajax({
type: "POST",
url: "Default.aspx/fetchcolumn",
data: '{}',
contentType: "application/json;charset=utf-8",
dataType: "json",
success: OnSuccess1,
error: OnErrorCall1
});
function OnSuccess1(response) {
var objdata1 = (response.d);
var pm1 = JSON.parse(objdata1);
var len1 = objdata1.length;
arr1 = $.map(pm1, function(n, i) {
var arr_temp1 = {
0: n.name
}
arrcolumn[i] = n.name;
return arr_temp1;
});
arrcolumn = jQuery.grep(arrcolumn, function(value) {
return value != removeItem;
});
arrcolumn = jQuery.grep(arrcolumn, function(value) {
return value != removeItem1;
});
alert(arrcolumn);
}
function OnErrorCall1(response) {
alert("unable to fecth");
}
function OnSuccess(response) {
var objdata = (response.d);
var pm = JSON.parse(objdata);
var len = objdata.length;
arr = $.map(pm, function(n, i) {
var arr_temp = {
0: n.name1,
1: n.os,
2: n.cn,
3: n.pns,
4: n.dbms,
5: n.se,
6: n.c
}
arrname[i] = n.name1;
arrmark[i] = [n.os, n.cn, n.pns, n.dbms, n.se, n.c];
return arr_temp;
});
//alert(arrcolumn);
alert(arrname);
alert(arrmark);
}
function OnErrorCall(response) {
alert("error occured");
}
}
這段代碼和問題真的很難理解,特別是因爲您使用了類似的壓縮變量名稱。你想達到什麼目的?你能給出一個簡單的,格式化的例子,說明什麼可行,哪些不行? – moopet
也許你的'OnSuccess1'在'OnSuccess'之前執行? Ajax是異步的,並且需要花費不同的時間來完成 – Justinas
你不能保證哪一個會首先完成,使它們串聯 –