ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.59k stars 1.33k forks source link

× TypeError: superagent.post(...).set(...).send(...).charset is not a function #1550

Closed PHPJourney closed 4 years ago

PHPJourney commented 4 years ago

I get this error.

code example

// save name ajax.js
import api from '../config/api';
const superagent = require('superagent');
// import storeConfig from "../store";
// import initialState from '../reducers/initialState';

// const store = storeConfig(initialState);
let token = '';
let cid = 0;
const fetch = function(url, method, data={}, header={}){
    console.log(superagent);
    switch(method.toLowerCase()){
        case 'post':
            return superagent.post(api.baseUrl+url).set({
                'token': token,
                'cid': cid,
                'Accept': 'application/json',
                header
            }).send(data).charset('utf-8').end((err, res)=>{
                return res;
            });
        break;
        case 'get':
            return superagent.get(api.baseUrl+url).set({
                'token': token,
                'cid': cid,
                'Accept': 'application/json',
                header
            }).query(data).charset('utf-8').end((err, res)=>{
                return res;
            });
        break;
    }
};
export default fetch;

install

npm install superagent --save-dev

quote

import fetch from 'util/ajax'
fetch(api.login, 'post', {}) 

/*****/

Sorry,not charset .

i'm remove charset can doing.