在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ Axios跨域POST請(qǐng)求參數(shù)為什么不能使Object

Axios跨域POST請(qǐng)求參數(shù)為什么不能使Object

服務(wù)端PHP已經(jīng)開啟了跨域

header('Access-Control-Allow-Origin:*');

前端用Axios發(fā)送跨域請(qǐng)求

instance.post("/reward", {...reward}).then((response) => {
      let serverData = response.data
      if (serverData.flag) {
        cb(serverData.ret)
      } else {
        ecb(serverData.error)
      }
    }).catch((error) => {
      console.log(error)
      ecb(error)
    })

所有的其他設(shè)置均使用默認(rèn)

問題:這個(gè)請(qǐng)求會(huì)觸發(fā)預(yù)檢測發(fā)送一個(gè)OPTIONS請(qǐng)求,恰巧服務(wù)端Nginx貌似不支持OPTIONS請(qǐng)求。
但是如果參數(shù)是JSON.stringify轉(zhuǎn)化后的字符串,就能夠正??缬?。
(手動(dòng)設(shè)置過header的content-type,均無效)

回答
編輯回答
茍活

恰恰相反,nginx是最容易支持OPTIONS請(qǐng)求的服務(wù)器,只需要在配置里添加以下幾行就可以了:

location / {
    if ($request_method = OPTIONS ) {
        add_header Content-Length 0;
        add_header Content-Type text/plain;
        return 200;
    }
}
2017年3月9日 23:11