現在試試這個:
// initialize here
var requestCallback = new MyRequestsCompleted({
numRequest: 3,
});
var urls = ["http://www.test.com/users/", "http://www.example.com/users/", "http://www.test.org/users/"]
$.each(urls, function(index, value) {
$.ajax({
type: "POST",
data: 'cache=yes',
url: value + get_back + "",
success: requestCallback.requestComplete(true)
});
});
var MyRequestsCompleted = (function() {
var numRequestToComplete, requestsCompleted, callBacks, singleCallBack;
return function(options) {
if (!options) options = {};
numRequestToComplete = options.numRequest || 0;
requestsCompleted = options.requestsCompleted || 0;
callBacks = [];
var fireCallbacks = function() {
alert("Reset cache successful");
for (var i = 0; i < callBacks.length; i++) callBacks[i]();
};
if (options.singleCallback) callBacks.push(options.singleCallback);
this.addCallbackToQueue = function(isComplete, callback) {
if (isComplete) requestsCompleted++;
if (callback) callBacks.push(callback);
if (requestsCompleted == numRequestToComplete) fireCallbacks();
};
this.requestComplete = function(isComplete) {
if (isComplete) requestsCompleted++;
if (requestsCompleted == numRequestToComplete) fireCallbacks();
};
this.setCallback = function(callback) {
callBacks.push(callBack);
};
};
});
,我們在這裏列出所有你要張貼到JavaScript數組中的URL,然後使用jQuery的$。每次遍歷所有的URL,做一個AJAX POST到每個一。
希望這會有所幫助。
什麼是你想要的目的。有點透視會幫助..雖然它可能發佈到多個網址使用1 ajax請求 – Baz1nga
我試圖重新緩存多個頁面 –