javascript - fetch从php接收到的数据没办法通过.json()进行解析,结果始终是undefined

WBOY
Release: 2016-06-06 20:20:58
Original
1575 people have browsed it

后端代码:
javascript - fetch从php接收到的数据没办法通过.json()进行解析,结果始终是undefined

前端代码:
javascript - fetch从php接收到的数据没办法通过.json()进行解析,结果始终是undefined

返回的数据:
javascript - fetch从php接收到的数据没办法通过.json()进行解析,结果始终是undefined

注意到了statusText也是undefined,这种情况,应该是后端的问题,请问,后端需要如何修改?

谢谢!

回复内容:

后端代码:
javascript - fetch从php接收到的数据没办法通过.json()进行解析,结果始终是undefined

前端代码:
javascript - fetch从php接收到的数据没办法通过.json()进行解析,结果始终是undefined

返回的数据:
javascript - fetch从php接收到的数据没办法通过.json()进行解析,结果始终是undefined

注意到了statusText也是undefined,这种情况,应该是后端的问题,请问,后端需要如何修改?

谢谢!

在@HJin_me 的提示下,我发现,自己在匿名函数中使用了{},这样,数据没有返回,所以最终的结果就是undefined的!如果只有一行代码,那么,可以不添加{},同时也不需要return,就可以返回数据了

break;改为exit;试试,会不会还有东东输出。
后端的地址能不能直接在网页中打开,看看最终输出的是什么?
一般测试我用firefox和firebug,返回的数据很容易看,这里的返回数据看得不是很明白,可能是我不习惯。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!