Skip to content

Commit

Permalink
Enhance requestOkText example.
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Jacobson authored and domenic committed Apr 21, 2013
1 parent 4f5a18d commit 5cbbfe8
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,12 @@ function requestOkText(url) {
if (request.status === 200) {
deferred.resolve(request.responseText);
} else {
onerror();
deferred.reject(new Error("Status code was " + request.status));
}
}

function onerror() {
deferred.reject("Can't XHR " + JSON.stringify(url));
deferred.reject(new Error("Can't XHR " + JSON.stringify(url)));
}

function onprogress(event) {
Expand All @@ -563,6 +563,21 @@ function requestOkText(url) {
}
```

Below is an example of how to use this ``requestOkText`` function:

```javascript
requestOkText("http://localhost:3000")
.then(function (responseText) {
// If the HTTP response returns 200 OK, log the response text.
console.log(responseText);
}, function (error) {
// If there's an error or a non-200 status code, log the error.
console.error(error);
}, function (progress) {
// Log the progress as it comes in.
console.log("Request progress: " + Math.round(progress * 100) + "%");
});
```

### The Middle

Expand Down

0 comments on commit 5cbbfe8

Please sign in to comment.