Heim  >  Artikel  >  Backend-Entwicklung  >  post - thinkphp I方法获取变量的问题?

post - thinkphp I方法获取变量的问题?

WBOY
WBOYOriginal
2016-08-25 10:37:191012Durchsuche

一直用thinkPHP的I方法来获取js ajax过来的数据,I方法可以接收 post 或者 get 方法传过来的数据,但是今天在接收js 传过来的数组时(用 JSON.stringify转化成了字符串),用I方法接收不到数据,但是其他的数据可以正常接收,用$_POST[]方法就可以正常接收数据了,这个是什么情况?

回复内容:

一直用thinkPHP的I方法来获取js ajax过来的数据,I方法可以接收 post 或者 get 方法传过来的数据,但是今天在接收js 传过来的数组时(用 JSON.stringify转化成了字符串),用I方法接收不到数据,但是其他的数据可以正常接收,用$_POST[]方法就可以正常接收数据了,这个是什么情况?

I('post.data','','strip_tags');
过滤一下试试

你把I方法的过滤参数加上试试呢!比如你要接收的json字符串加上htmlspecialchars或者strip_tags

<code>//试试看能不能接收到
I('json', '', 'htmlspecialchars');
I('json', '', 'strip_tags');</code>

I方法会识别 ajax 的data type。 如果data type为get,那么I方法默认 参数为get。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn