let choiceContext = [];
let nameList = [];
const data = {
resource_id: '9329755c-6406-4894-88b7-e7b04ccdfecc',
limit: 10,
};
$.ajax({
url: 'https://www.data.brisbane.qld.gov.au/data/api/3/action/datastore_search',
data: data,
dataType: 'jsonp',
cache: true,
success:
function sendIN(data){
$.each(data.result.records, function(recordKey, recordValue) {
//some code about addding data to choiceContext
return choiceContext; //assume a result
});
}
});
const answer = sendIN();
嗨,在上面的这些代码中,有一个叫做sendIN
的函数,我只是想在ajax中使用它的结果…但这行不通。
然而,我已经尝试使用document.Cookie
:
let choiceContext = [];
let nameList = [];
const data = {
resource_id: '9329755c-6406-4894-88b7-e7b04ccdfecc',
limit: 10,
};
$.ajax({
url: 'https://www.data.brisbane.qld.gov.au/data/api/3/action/datastore_search',
data: data,
dataType: 'jsonp',
cache: true,
success:
function sendIN(data){
$.each(data.result.records, function(recordKey, recordValue) {
//some code about addding data to choiceContext
document.Cookie = choiceContext;
});
}
});
const answer = document.Cookie;
它可以工作,但是它不能存储足够的数据,所以我需要找到另一种方法来实现这一点。
真的谢谢!
对于第一个请求,您可以这样做:
let choiceContext = [];
let nameList = [];
const data = {
resource_id: '9329755c-6406-4894-88b7-e7b04ccdfecc',
limit: 10,
};
let succesFunctionSendIN = function sendIN(data){
$.each(data.result.records, function(recordKey, recordValue) {
//some code about addding data to choiceContext
return choiceContext; //assume a result
});
};
$.ajax({
url: 'https://www.data.brisbane.qld.gov.au/data/api/3/action/datastore_search',
data: data,
dataType: 'jsonp',
cache: true,
success: succesFunctionSendIN
});
const answer = succesFunctionSendIN({result[]});
现在你有一个函数引用">succesFunctionSendIN">
第二:你可以使用HTML网页存储。
HTML web storage提供了两个对象用于在客户端上存储数据:
- 窗口。localStorage -存储没有过期日期的数据(最大大小5Mb)
- 窗口。sessionStorage -存储一个会话的数据(当浏览器选项卡关闭时数据丢失)仅受系统内存限制
在使用web存储之前,请检查浏览器是否支持localStorage和sessionStorage:
你的成功函数是这样的。
success: function(data) {
if (typeof(Storage) !== "undefined") {
localStorage.choiceContext = data.result.records;
} else {
// Sorry! No Web Storage support..
}
}