mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2024-10-06 17:22:12 +08:00
added usage description for abort()
This commit is contained in:
parent
bc90ae85fb
commit
f6736d9150
40
README.md
40
README.md
@ -404,6 +404,46 @@ cordova.plugin.http.downloadFile("https://google.com/", {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### abort<a name="abort"></a>
|
||||||
|
Abort a HTTP request. Takes the `requestId` which is returned by [sendRequest](#sendRequest) and its shorthand functions ([post](#post), [get](#get), [put](#put), [patch](#patch), [delete](#delete), [head](#head), [uploadFile](#uploadFile) and [downloadFile](#downloadFile)).
|
||||||
|
|
||||||
|
If the request already has finished, the request will finish normally and the abort call result will be `{aborted: false}`.
|
||||||
|
|
||||||
|
If the request is still in progress, the request's `failure` callback will be invoked with response `{status: -8}`, and the abort call result `{aborted: true}`.
|
||||||
|
|
||||||
|
:warning: Not supported on iOS.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// start a request and get its requestId
|
||||||
|
var requestId = cordova.plugin.http.downloadFile("https://google.com/", {
|
||||||
|
id: '12',
|
||||||
|
message: 'test'
|
||||||
|
}, { Authorization: 'OAuth2: token' }, 'file:///somepicture.jpg', function(entry) {
|
||||||
|
// prints the filename
|
||||||
|
console.log(entry.name);
|
||||||
|
|
||||||
|
// prints the filePath
|
||||||
|
console.log(entry.fullPath);
|
||||||
|
}, function(response) {
|
||||||
|
// if request was actually aborted, failure callback with status -8 will be invoked
|
||||||
|
if(response.status === -8){
|
||||||
|
console.log('download aborted');
|
||||||
|
} else {
|
||||||
|
console.error(response.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//...
|
||||||
|
|
||||||
|
// abort request
|
||||||
|
cordova.plugin.http.abort(requestId, function(result) {
|
||||||
|
// prints if request was aborted: true | false
|
||||||
|
console.log(result.aborted);
|
||||||
|
}, function(response) {
|
||||||
|
console.error(response.error);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Browser support<a name="browserSupport"></a>
|
## Browser support<a name="browserSupport"></a>
|
||||||
|
|
||||||
This plugin supports a very restricted set of functions on the browser platform.
|
This plugin supports a very restricted set of functions on the browser platform.
|
||||||
|
Loading…
Reference in New Issue
Block a user