簡體   English   中英

數據未傳入 axios post 請求

[英]Data not passing in axios post request

我正在使用axios調用 post 請求,如下所示:

axios.post(this.api+'&action='+this.action+'&wftkn='+this.wftkn, {name: 'Abcd'}).
   then((res)=>{

   });

當我檢查網絡選項卡時,我看不到請求標頭中傳遞的數據。 在這種情況下會出現什么問題?

在此處輸入圖像描述 編輯:添加了控制台錯誤。

請嘗試以下方法:

axios.post(this.api, { name: 'Abcd' }, {
  params: {
    action: this.action,
    wftkn: this.wftkn,
  }
}).then((res)=>{});

這是瀏覽器的一種保護,您正在請求其他域上的資源,因此您需要設置一個響應標頭:

Access-Control-Allow-Origin: http://localhost:8000

https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

當您使用特定參數時,Axios 將適用於大多數 Web 服務器。 由於GETPOST沖突或錯誤/缺少標頭,通常會發生此問題。

axios.request({
  method: 'POST',
  url: `https://stackoverflow.com/end-point`,
  headers: {
    'Authorization': 'token'
  },
  data: {
    title: 'abc'
  },

})```

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM