亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過超級代理在本地項目上響應 Ajax 請求

通過超級代理在本地項目上響應 Ajax 請求

阿波羅的戰車 2022-11-27 16:54:35
我想通過 superagent 插件/庫將 AJAX 請求發送到存儲在 backend/hi.php 中的 php 文件這是 php 文件:<?phpecho "hi";我基本上想從 php 文件中取回 hi。這是請求發生的 reducers/index.js 中的 reducerimport superagent from 'superagent';import jsonp from 'superagent-jsonp';let initialState = null;function reducer(state = initialState,action) {    if(action.type=="SEARCH") {        let url= "/backend/hi.php";        superagent.get(url).end(function(err, res){            console.log(res);        });    }    else {        return state;    }}export default reducer;我在控制臺中得到的不是字符串“hi”,而是以下內容:    Response1.  accepted: false2.  badRequest: false3.  body: null4.  charset: "UTF-8"5.  clientError: false6.  created: false7.  error: false8.  forbidden: false9.  header: {accept-ranges: "bytes", connection: "keep-alive", content-encoding: "gzip", content-type: "text/html; charset=UTF-8", date: "Tue, 21 Jul 2020 15:39:42 GMT", …}10. headers: {accept-ranges: "bytes", connection: "keep-alive", content-encoding: "gzip", content-type: "text/html; charset=UTF-8", date: "Tue, 21 Jul 2020 15:39:42 GMT", …}11. info: false12. links: {}13. noContent: false14. notAcceptable: false15. notFound: false16. ok: true17. redirect: false18. req: Request {_query: Array(0), method: "GET", url: "/backend/hi.php", header: {…}, _header: {…}, …}19. serverError: false20. status: 20021. statusCode: 20022. statusText: "OK"23. statusType: 225. type: "text/html"26. unauthorized: false27. unprocessableEntity: false28. xhr: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ?, …}29. __proto__: Object這是我的文件夾結構:如何將 Ajax 請求正確發送到 hi.php?
查看完整描述

1 回答

?
白板的微信

TA貢獻1883條經驗 獲得超3個贊

我認為后端 api 正在返回 null 作為正文。這可能是您的 API 的問題。嘗試從瀏覽器訪問 api 并查看它是否返回數據



查看完整回答
反對 回復 2022-11-27
  • 1 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號