Confirmed users
398
edits
| Line 11: | Line 11: | ||
readonly attribute long numAllBatches; | readonly attribute long numAllBatches; | ||
Promise | Promise getBatches(); // return submitted batches of the same origin. | ||
Promise | Promise getAllBatches(); // return all submitted batches, not strict by the same origin if with the permission | ||
} | } | ||
| Line 29: | Line 29: | ||
readonly attribute unsigned short state; | readonly attribute unsigned short state; | ||
Promise | Promise createXMLHttpRequest(); | ||
/* | /* | ||
* The batch is ready for a transmission and known by the user agent. | * The batch is ready for a transmission and known by the user agent. | ||
| Line 36: | Line 36: | ||
* from NOTSUBMITTED to WAITING. | * from NOTSUBMITTED to WAITING. | ||
*/ | */ | ||
Promise | Promise submit(); | ||
Promise | Promise start(); // Start the transmission. The state is transited from WAITING to SENDING. | ||
/* | /* | ||
* Stop the transmission. | * Stop the transmission. | ||
| Line 44: | Line 44: | ||
* until completed or failed for requests in sending. | * until completed or failed for requests in sending. | ||
*/ | */ | ||
Promise | Promise stop(boolean force); | ||
Promise | Promise drop(); // remove the batch from the user agent. | ||
Promise getRequests(); | |||
} | } | ||
| Line 51: | Line 53: | ||
readonly attribute XHRBatch batch; // The batch this request belonging to. | readonly attribute XHRBatch batch; // The batch this request belonging to. | ||
Promise<boolean> removeFromBatch(); // Remove this request from the batch belonged to. | Promise<boolean> removeFromBatch(); // Remove this request from the batch belonged to. | ||
} | |||
== Examples == | |||
let batches_defer = navigator.XHRBatch.getBatches(); | |||
batches_defer.then(batches => { | |||
for (let i in batches) { | |||
let batch = batches[i]; | |||
console.log("Batch Name: " + batch.name); | |||
console.log(" Description: " + batch.description); | |||
} | |||
}); | |||
function onNetworkAvailable() { | |||
let allBatches_defer = navigator.XHRBatch.getAllBatches(); | |||
allBatches_defer.then(batches => { | |||
for (let i in batches) { | |||
let batch = batches[i]; | |||
if (batch.state == navigator.XHRBatch.WAITING) { | |||
batch.start(); | |||
} | |||
} | |||
} | |||
} | |||
function onBatchCompleted() { | |||
let batches_defer = navigator.XHRBatch.getBatches(); | |||
batches_defer.then(e => { | |||
for (let i in e.batches) { | |||
let batch = e.batches[i]; | |||
if (batch.state != navigator.XHRBatch.COMPLETED) | |||
continue; | |||
batch.drop(); | |||
batch.getRequests().then(e => { | |||
let error_count = 0; | |||
for (let i in e.requests) { | |||
let xhr = e.requests[i]; | |||
if (xhr.status != 200) { | |||
error_count++; | |||
} | |||
} | |||
console.log("Batch " + e.batch.name + " is completed!"); | |||
console.log(" " + error_count + " errors!"); | |||
} | |||
} | |||
} | |||
} | } | ||