wx.request Is sponsored by the HTTPS request , Here is its basic usage , There is no more verbosity here


2. encapsulation GET

stay utils Create httpclient.js

var app = getApp();
function get(param) {
var mydata = {}; var header = param.header;
header = {
'content-type': 'application/json'
} mydata = param.data || {};
mydata['sessionId'] = app.globalData.sessionId; wx.request({
url: app.globalData.serverAddress + param.url,
data: mydata,
header : header,
method: "GET",
success: param.success,
fail: param.fail,
complete: function () {
// complete
module.exports = {
get: get

Call method example

var httpClient = require('../../utils/httpclient');
url: 'Account/Get',
data: this.data.userInfo,
success: function (res) {
//this is success
fail: function () {
that.showTopTips(' Encounters an error !');

3. encapsulation POST

post Also similar

I'll continue to add when I have time

Welcome to this series : Wechat applet development tutorial Directory

Wechat applet HTTPS More related articles requested

  1. About wechat applet Request Request error handling

    Learning wechat app request On request , At the beginning “ Not in the following list of legal domain names , Please refer to the text ” Error of , And then there was a strange newspaper “400 Bad Request” error , After half a day of research , We finally got it , Let's share our mistakes ...

  2. Monitoring wechat apps wx.request request was aborted

    In wechat applet , The main interface function to interact with the background server is wx.request(), Used to initiate HTTPS Network request . Its importance is self-evident . However , But we often encounter the problem of request failure , I specially Google "wx.request ...

  3. Wechat applet needs https Think about the entrepreneurial opportunities behind the scenes

    Recently, I pay more attention to wechat apps , And the background of wechat app must be mandatory https, https relative http The cost is much higher . Here I feel like 2 Opportunities (1) Provide https Transit servers , Charge by traffic (2)  Wechat applet ...

  4. Wechat applet development :http request

    Network communication in wechat applet , Can only communicate with the specified domain name , Wechat applets include four types of network requests . Ordinary HTTPS request (wx.request) Upload files (wx.uploadFile) Download the file (wx.downlo ...

  5. [ turn ] Wechat applet development :http request

    In this paper, from :http://www.cnblogs.com/dragondean/p/5921079.html Network communication in wechat applet , Can only communicate with the specified domain name , Wechat applets include four types of network requests . Ordinary ...

  6. Wechat applet wx.request Request server json Data and render to the page

    [ Original text ]: https://blog.csdn.net/weixin_39927850/article/details/79766259 Wechat app data can't be written dead , It must be combined with the database to make data more ...

  7. Wechat applet wx.request Request to use POST The data can't be transferred in the background

    Wechat applet wx.request request ,method Set to POST And deliver data to the background , However, from the information returned by the background, the background did not get the data transferred wx.request({              url: 'url' ...

  8. Wechat applet request Synchronization request

    Today, I used it conveniently when I was working on wechat apps async,await It doesn't work , Later, I checked for a while , I don't support , There's no way to change the implementation wx.request Synchronous request scheme Sacrifice promise Let's do it , Here is the code , Jane ...

  9. Solve wechat applet configuration https The problem of failure

    Get a wechat app project , Need configuration https Secure links ( Why must we use https I won't repeat ), Imagine this already mature process , It shouldn't be a big problem , It turned out to be quite unexpected , I fell into a big hole , It's been a long time . Apply for certificate configuration ...

Random recommendation

  1. subject : seek 1+2+...+n, Ask not to use multiplication and division 、for、while、if、else、switch、case、 And other keywords and conditional judgment statements (A?B:C)

    #include <iostream> using namespace std; int add_(int a,int b){ return 0; } int Add(int i,bool ...

  2. HookIAT Start up procedure for

    // Start the program .cpp : Defines the entry point for the console application . // #include "stdafx.h" #include <Windows.h> #include &l ...

  3. javascript note ——js The blocking characteristics of [ Reprint ]

    JS It has blocking characteristics , When the browser is executing js Code , You can't do other things at the same time , namely <script> Every time it appears, it makes the page wait for the script to parse and execute ( Regardless of JS Is it embedded or out of the chain ),JS After the code is executed , To continue rendering the page . ...

  4. leetCode 31.Next Permutation ( Next dictionary order ) Ideas and methods of solving problems

    Next Permutation  Implement next permutation, which rearranges numbers into the lexicographically ne ...

  5. C++ Templates : Euler function

    A single Euler function int eular(int n){ int ret=1,i; for(i=2;i*i<=n;i++) if(n%i==0){ n/=i,ret*=i-1; while(n%i==0 ...

  6. Python Web- Week six -JSON and the REST Architecture(Using Python to Access Web Data)

    1.JavaScript Object Notation JSON 1.JSON The official introduction  http://www.json.org/json-zh.html 2.json1.py import jso ...

  7. jvm Memory allocation ( turn )

    In depth understanding of JVM—JVM Memory model  http://www.cnblogs.com/dingyingsi/p/3760447.html We know , Computer CPU Interaction with memory is the most frequent , Memory is our cache ...

  8. [Algorithm] Given the root to a binary tree, return the deepest node

    By given a binary tree, and a root node, find the deepest node of this tree. We have way to create n ...

  9. js Realize the parabola

    This is a very simple way , Take advantage of css3 Of transition attribute <!DOCTYPE html> <html lang="en" style="widt ...

  10. USB3.0 Test and instructions

    summary AC6102 There's one integrated on it Cypress High performance USB3.0 Transmission chip CYUSB3014,Cypress be called EZ-USBFX3. The chip has strong performance , Powerful , The interface is simple , It is very suitable for all kinds of high speed data ...