npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xlou/ajax

v1.0.2

Published

Front-end tool for sending AJAX requests

Readme

Languages

Introduction

  • Front-end tool for sending AJAX requests

Usage

Using in Traditional Projects

<script src="https://unpkg.com/@xlou/[email protected]/dist/umd/ajax.min.js"></script>
<!-- It's recommended to download and use the file locally -->
<script>
  /* After including this JS file, the ajax object will be available on the window */
  ajax({
    url: "http://127.0.0.1:3000/post",
    method: "post",
    params: {
      id: 1
    },
    data: {
      name: "Tom"
    }
  })
  .then(res => {
    console.log("response", res.response)
  })
</script>

Using in Vue, React, Angular, and Other Node Projects

Installation

npm i @xlou/ajax

In main.js or main.ts

/* Using the entire package */
import ajax from '@xlou/ajax'

ajax({
  url: "http://127.0.0.1:3000/post",
  method: "post",
  params: {
    id: 1
  },
  data: {
    name: "Tom"
  }
})
.then(res => {
  console.log("response", res.response)
})

API

ajax

Send an AJAX request.

Parameter Details

interface GeneralObject {
  [prop: string]: string | number | boolean | null | undefined
}

interface AjaxOptions {
  (args: AjaxArguments): Promise<AjaxRequest>
  queryString?: (obj: GeneralObject, bol?: boolean) => string
  getUrlParam?: (url: string, data: GeneralObject | string) => string
  getHeaders?: (arg: string | null) => GeneralObject
  ContentType?: ContentType
}

interface AjaxArguments {
  method?: string
  headers?: GeneralObject,
  url: string,
  params?: GeneralObject,
  data?: any,
  responseType?: ResType,
  withCredentials?: boolean,
  timeout?: number,
  uploadProgress?: (ev: Event) => any
  downloadProgress?: (ev: Event) => any
}

interface AjaxRequest {
  config: AjaxArguments
  response: any
  headers: GeneralObject
  request: XMLHttpRequest
  status: number
  statusText: string
}

const ajax: AjaxOptions = function(args: AjaxArguments): Promise<AjaxRequest>

Usage Example

ajax({
  url: "http://127.0.0.1:3000/post", // Specify the request address.
  method: "post", // Set the request type.
  headers: { // Set request header parameters.
    "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
  },
  params: { // Convert and append as query parameters to the request URL.
    id: 1
  },
  data: { // Convert the request body parameters based on the Content-Type.
    name: "Tom"
  },
  uploadProgress(ev) { }, // Add a listener for upload progress.
  downloadProgress(ev) { } // Add a listener for download progress.
})
.then(res => {
  console.log("post-data-urlencoded", res.response)
})

queryString

Convert an object into URL parameters.

Parameter Details

queryString?: (obj: GeneralObject, bol?: boolean) => string

Usage Example

/* Script Tag Import */
ajax.queryString({
  id: 1,
  type: "hello"
})
// id=1&type=hello

/* Use ECMAScript Module import */
import { queryString } from '@xlou/ajax'
queryString({/* ... */})

getUrlParam

Convert an object into URL parameters and determine whether to add '?' based on the URL.

Parameter Details

getUrlParam?: (url: string, data: GeneralObject | string) => string

Usage Example

/* Script Tag Import */
ajax.getUrlParam("www.xxx.com", {
  id: 1,
  type: "hello"
})
// ?id=1&type=hello

ajax.getUrlParam("www.xxx.com?key=a", {
  id: 1,
  type: "hello"
})
// id=1&type=hello

/* Use ECMAScript Module import */
import { getUrlParam } from '@xlou/ajax'
getUrlParam({/* ... */})

getHeaders

Convert the result returned by xhr.getAllResponseHeaders() into an object.

Parameter Details

getHeaders?: (arg: string | null) => GeneralObject

Usage Example

/* Script Tag Import */
ajax.getHeaders(xhr.getAllResponseHeaders())

/* Use ECMAScript Module import */
import { getHeaders } from '@xlou/ajax'
getHeaders(xhr.getAllResponseHeaders())

ContentType

An object that contains some Content-Type.

Parameter Details

enum ContentType {
  json = "application/json;charset=UTF-8",
  urlencoded = "application/x-www-form-urlencoded;charset=UTF-8",
  formData = "multipart/form-data",
  text = "text/plain;charset=UTF-8",
  xml = "application/xml;charset=UTF-8",
  stream = "application/octet-stream"
}

Usage Example

/* Script Tag Import */
ajax.ContentType

/* Use ECMAScript Module import */
import { ContentType } from '@xlou/ajax'