我想实现“缓存”以使用localStorage
. request ( requestData
) 的参数将是唯一标识符。这是我的代码:
App = {};
App.Service = function(name) {
this.name = name;
};
App.Service.prototype.sendRequest = function(requestData) {
// process request data somehow and store to local variable
var identifier = $.param(requestData);
$.ajax({
url: 'web/api',
success: function(data) {
// can identifier differ from calculated before ajax call?
// for example if someone else start this method in the same time?
localStorage.setItem(identifier, data);
},
error: function(jqXHR, textStatus, errorThrown) {
// handle error
},
type: "POST",
data: requestData
});
};
这是我的问题:假设我已经多次启动了 sendRequest 方法。每个success
回调方法是自己操作identifier
还是混合在一起(换句话说,错误的标识符将分配给响应数据)?