我想通过 superagent 插件/库将 AJAX 请求发送到存储在 backend/hi.php 中的 php 文件
这是 php 文件:
<?php
echo "hi";
我基本上想从 php 文件中取回 hi。
这是请求发生的 reducers/index.js 中的 reducer
import 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”,而是以下内容:
Response
1. accepted: false
2. badRequest: false
3. body: null
4. charset: "UTF-8"
5. clientError: false
6. created: false
7. error: false
8. forbidden: false
9. 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: false
12. links: {}
13. noContent: false
14. notAcceptable: false
15. notFound: false
16. ok: true
17. redirect: false
18. req: Request {_query: Array(0), method: "GET", url: "/backend/hi.php", header: {…}, _header: {…}, …}
19. serverError: false
20. status: 200
21. statusCode: 200
22. statusText: "OK"
23. statusType: 2
25. type: "text/html"
26. unauthorized: false
27. unprocessableEntity: false
28. xhr: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
29. __proto__: Object
这是我的文件夹结构:
如何将 Ajax 请求正确发送到 hi.php?
白板的微信
相关分类