다른 서버에서 호스팅되는 json 파일을 찾는 javascript/ajax 함수가 있습니다. JSON 파일보다 오래된 1 시간 Ajax를 사용하여 캐시 파일을 저장하려면 어떻게해야합니까?
- 가져 오기 JSON 파일 : 나는 다음과 같은 작업을 수행 할 제 기능을해야합니다 이 1 시간보다 오래된 밤은 경우 사용하는 데이터
- 이 1 시간보다 오래된 경우 - 외부 서버에서 다시 다운로드 및 덮어 쓰기 로컬 버전
현재 내 함수는 호출 될 때마다 외부 서버에서 데이터를 가져옵니다. 이 캐싱 기능을 추가해야하지만 어떻게 처리해야하는지 확신 할 수 없습니다.
누구든지 조언을 제공 할 수 있습니까? 여기
내 코드 : 사전에
function ajaxLoad(page,url,type,variety,category , widgetClickedId)
{
/*
* Checking the clicked id is the same as passed in one
* TODO refactor so the clicked id only ever gets passed
*/
if(widgetId != widgetClickedId && widgetClickedId != undefined)
{
return false;
}
var website = $('#button-print'+widgetId).data("website");
var page = $('#button-print'+widgetId).data("page");
$.ajax({
type: 'GET',
url: 'www.myothersite.com/api/v1/productchoice.json?website='+website,
async: true,
jsonp: 'callback',
dataType: 'jsonp',
success: function(productchoice)
{
if(productchoice['brand'+widgetId] == 'null' || productchoice['brand'+widgetId] == undefined)
{
productchoice['brand'+widgetId] = '';
}
//check that all values are not null , if not , then show the widget
if( productchoice['brand'+widgetId] == ''
&& productchoice['subject'+widgetId] == ''
&& productchoice['market'+widgetId] == ''
&& productchoice['type'+widgetId] == ''
&& productchoice['bookazinebrands'+widgetId] == '')
{
//is this corect?
$('#gdmContainer'+widgetId).hide();
//return false;
}
else
{
$('#gdmContainer'+widgetId).show();
}
setRibbons(productchoice.ribbonTop , productchoice.ribbonBottom);
getProductChoice(productchoice);
setLoveTitle(productchoice);
setDefaultBtn(productchoice['defaultBtn'+widgetId]);
return productchoice;
}
});
감사합니다!