Socket
Socket
Sign inDemoInstall

xhr-status

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    xhr-status

Normalize XHR status code/text across various of environments


Version published
Weekly downloads
7.8K
decreased by-0.19%
Maintainers
1
Install size
8.04 kB
Created
Weekly downloads
 

Readme

Source

xhr-status

Made by unshiftVersion npmBuild StatusDependenciesCoverage StatusIRC channel

Normalize the XHR status codes across various of environments. This eliminates all the odd browser bugs that you might run in to while working with XHR requests in browsers:

  • Captures thrown errors when accessing statusText
  • Normalizes the 1233 status code in Internet Explorer for 204 content.
  • Normalizes the 0 status code to 200 for file:// requests.

Installation

The module is released in the public npm registry and can be installed by running:

npm install --save xhr-status

Usage

This module exports a single function. The returned function accepts one single argument which is a reference to the xhr instance that you've created. It will return an object with the following keys:

  • code The XHR status code.
  • text The XHR status text.

See for an implementation example:

'use strict';

var xhrstatus = require('xhr-status')
  , xhr = new XMLHTTPRequest.

xhr.open('GET', 'http://google.com/gen_204', true);
xhr.onload = function () {
  var status = xhrstatus(xhr);

  console.log(status.code) // 204
  console.log(status.text) // OK
};

xhr.send();

License

MIT

Keywords

FAQs

Last updated on 15 Jan 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc