1. 程式人生 > >微信小程式 豆瓣專案中wx.request遇到的問題

微信小程式 豆瓣專案中wx.request遇到的問題

首先說遇到的問題

index.js

var API_URL = 'https://api.douban.com/v2/movie/top250';
Page({
  data: {
    movies: []
  },
  onLoad: function () {
    wx.showToast({
      title: "載入中",
      icon: "loading",
      duration: 10000
    });
    wx.request({
      url: 'https://api.douban.com/v2/movie/top250',
      data: {},
      header: {
        'Content-Type': 'application/json'
      }, // 設定請求的 header
      success: function (res) {
        // success
        console.log(res);
      }
    });
  }

})

後來把request中的header改成 'application/x-www-form-urlencode'  之後,就沒有問題了
至於為什麼,我也不清楚,哈哈哈,待以後慢慢學習吧