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

elegant-ajax

v1.0.0

Published

参考jQuery Ajax 尝试自己封装一下:

Readme

自定义封装Ajax

参考jQuery Ajax 尝试自己封装一下:

  • 新增支持 delay 延迟发送请求
  • 支持then操作

参数设置

url

  • 类型:String
  • 默认值: 当前页地址。发送请求的地址。

async

  • 类型:Boolean
  • 默认值: true。默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。
  • *注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。

data

  • 类型:String/Object
  • 发送到服务器的数据。支持字符串形式和对象形式ajax将自动转换为请求字符串格式。GET 请求中将附加在 URL 后。

dataType

  • 类型:String
  • 预期服务器返回的数据类型。服务器端返回的数据会根据这个值被解析后,传递给回调函数。

delay

  • 类型:Number
  • 延迟发送请求单位为毫秒数。

timeout

  • 类型:Number
  • 超时设置,单位为毫秒数。

success

  • 类型:Function
  • 请求成功调用的方法。

success

  • 类型:Function
  • 请求失败调用的方法。

安装

npm install simple-ajax

用法示例

const ajax = require('ajax')
 ......
    let params = {
        method:"get",
        url:"http://localhost:5001/user/list",
        data:"pageSize=10&pageNo=1",
        success:function(res){
            console.log(res)
            alert("请求成功")
            return res
        }

    }
    ajax(params).then((res)=>{
        console.log(res)
    })
 ......