我想通过 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?
添加回答
举报
0/150
提交
取消