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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jt-ajax

v1.0.0

Published

jt-ajax

Downloads

7

Readme

jt-ajax

与后端良好适配的ajax请求工具,可自动判断请求的返回状态,自动显示请求状态提示。

用法说明

#####引入到项目中

import r from 'jt-ajax';

#####提供的基本请求方法(method): get, post, put, del

#####调用方法: const p = r.method(url[, option])

  • url 以 "/" 开使,不允许访问当前页面之外的host
  • option 为 {}, 允许为空,不为空时可以传递如下内容:
  • data:body区传递的参数,请求为 post,put时有效,否则忽略
  • query: 作为QueryString附加至url后,减轻拼接参数的工作
  • path: 以同名替换至 url中以":"开始的路径段,比如 /user/:account/login 中:account将被替换
  • header:将放至Header区传递,如果有 content-type(不区分大小写) 存在,将覆盖默认的 Content-type

如果内置的基本请求不能满足使用,可以使用ajax方法:

const p = r.ajax(method, url[, option])

#####返回: 请求返回一个Promise p

#####p 提供如下回调(callback)接口:

start, success, fail, error, done

#####调用方法: p.callback(callable)

  • start 回调中的方法将直接执行,可以在发送前在此处做些准备工作 callable 可接收的参数:
  • success 将在执行成功(状态为200且服务器返回的 success 为 true)时调用,可接收的参数:
  • fail 操作失败(状态为200但服务器返回的 success 为 false)时执行,可接收的参数为:
                                 + error 请求错误(状态非200)
                                     <pre>
                                     err: 错误说明,有 code 和 msg 属性, 对code和msg属性进行修改,可以改变在请求状态栏显示的错误提示
                                     xhr: XMLHttpRequest
                                     q: 带有 resolve 和 reject 两个方法可供调用
                                     </pre>
                                 + done 请求完成,不管成功或是失败,都分执行,可以获得的参数为:
                                     <pre>
                                     xhr: XMLHttpRequest
                                     q: 带有 resolve 和 reject 两个方法可供调用

注: 调用q.resolve或q.reject将改变流程的走向。resolve后将执行后续的成功流程(如果数据未修复,将继续被判定为错误),reject后将执行后续的失败流程 ####示例: 获取菜单列表:

用户登录: