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 🙏

© 2024 – Pkg Stats / Ryan Hefner

steamer-net

v1.2.2

Published

ajax util

Downloads

22

Readme

steamer-net

NPM Version Travis Deps Coverage

ajax util for development

Options

  • url
    • [String] request url
  • type
    • [String] param type. Pass json POST data to Ajax when set type as json
    • default ''
    • json | ''
  • param
    • [Object]
    • jsonCbName [String] necessary if ajaxType is JSONP
  • success
    • [Function] success callback
  • error
    • [Function] error callback
    • errCode: -1 => xhr.onerror, -2 => xhr.ontimeout
  • timeout
    • [Integer] timeout (unit: ms)
  • ajaxType
    • [String] ajax type
    • default GET
    • POST | GET | JSONP | FORM
  • dataType
    • [String] returned data type
    • default json
    • json | text |
  • xhrFields
    • [Object]
    • { withCredentials: true or false }
  • headers
    • [Object] request headers
    • { 'Access-Control-Allow-Origin': '*' }

Functions

  • net.ajaxInit
net.ajaxInit({
    beforeRequest: function(opts) {
        opts.param.xsrf = 'xsrf';
        return opts;
    },
    beforeResponse: function(data, successCb, errorCb) {
        data.foo = 'bar';
        successCb(data);
    },
    dataReturnSuccessCondition: function(data) {
        return !data.errCode;
    },
});

dataReturnSuccessCondition will invoked after beforeResponse

  • net.ajax
net.ajax({
    url: baseUrl + "get_material_info.fcg",
    param: {
    	id: 1
    },
    ajaxType: 'POST',
    success: function(data){
       	// some code
    },
    error: function(xhr){
    	// some code
    }
});
  • net.ajaxGet
net.ajaxGet({
    url: baseUrl + "get_material_info.fcg",
    param: {
    	id: 1
    },
    success: function(data){
       	// some code
    },
    error: function(xhr){
    	// some code
    }
});
  • net.ajaxPost
net.ajaxPost({
    url: baseUrl + "get_material_info.fcg",
    param: {
    	id: 1
    },
    success: function(data){
       	// some code
    },
    error: function(xhr){
    	// some code
    }
})
  • net.ajaxJsonp
net.ajaxJsonp({
    url: baseUrl + "get_material_info.fcg",
    param: {
    	id: 1,
    	jsonCbName: "jsonpCb"
    },
    success: function(data){
       	// some code
    },
    error: function(xhr){
    	// some code
    }
})

Local data

If you would like to use local data, you can specify localData param.

net.ajaxPost({
    url: baseUrl + "get_material_info.fcg",
    param: {
        id: 1
    },
    localData: [{id: 1, name: "a"}],
    success: function(data){
        // some code
    },
    error: function(xhr){
        // some code
    }
})

Test

npm run test