如何將Java腳本中的ajax get函數參數與返回值一起傳出?JavaScript Pass函數參數與返回值一起
在下面的例子中,我想通過GetServer函數參數id
的價值帶來並使其功能returnValue
function getServerList(id) {
$.ajax({
type: "GET",
url: "/BackEndFunction/" + id,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: returnValue
});
}
function returnValue(Data) {
var _size = 0;
var id= id // passed from getserverlist
for (var i = 0; i< Data.length; i++) {
_size += Data[i]._size;
}
data_dictionary[id] = _size;
}
使其可訪問性如何exa ctly? 'returnValue'接受一個參數嗎? –
好點,錯過了,是的,總之,我會更新這個問題。 – JammAndTea
你可以嘗試像thid這樣的東西:如果像returnValue(param_id,responce)那樣聲明'returnValue',所以你可以使用'bind'就像'success:returnValue.bind(this,id)' – Grundy