PHP接收前端传值各种情况整理
原
荐
字数 535
阅读 13
收藏 0
PHP接收前端传值各种情况整理
服务端代码:
header('Access-Control-Allow-Origin:*');
var_dump($_POST);
exit;
情况
1) 传null
$.post('http://xxxxx.xx/index.php', {
"test": null
}, function(data, status) {
console.log(data);
});
结果:
array(1) {
["test"]=>
string(0) ""
}
2) 传''
代码:
$.post('http://xxxxx.xx/index.php', {
"test": ''
}, function(data, status) {
console.log(data);
});
结果:
array(1) {
["test"]=>
string(0) ""
}
3) 传'[]'
$.post('http://xxxxx.xx/index.php', {
"test": '[]'
}, function(data, status) {
console.log(data);
});
结果:
array(1) {
["test"]=>
string(2) "[]"
}
4) 传[]
$.post('http://xxxxx.xx/index.php', {
"test": []
}, function(data, status) {
console.log(data);
});
结果:
array(0) {
}
5) 传2个[]
$.post('http://xxxxx.xx/index.php', {
"test": [],
"test2": []
}, function(data, status) {
console.log(data);
});
结果:
array(0) {
}
6) 传{}
$.post('http://xxxxx.xx/index.php', {
"test": {}
}, function(data, status) {
console.log(data);
});
结果:
array(0) {
}
7) 传2个{}
$.post('http://xxxxx.xx/index.php', {
"test": {},
"test2": {}
}, function(data, status) {
console.log(data);
});
结果:
array(0) {
}
8) 传1个{}加1个非空对象
$.post('http://xxxxx.xx/index.php', {
"test": {},
"test2": {"a": 1}
}, function(data, status) {
console.log(data);
});
结果:
array(1) {
["test2"]=>
array(1) {
["a"]=>
string(1) "1"
}
}
9) 传[{}]
$.post('http://xxxxx.xx/index.php', {
"test": [{}]
}, function(data, status) {
console.log(data);
});
结果:
array(0) {
}
10) 传[[{}]]
$.post('http://xxxxx.xx/index.php', {
"test": [[{}]]
}, function(data, status) {
console.log(data);
});
结果:
array(0) {
}
11) 传'nil'
$.post('http://xxxxx.xx/index.php', {
"test": 'nil'
}, function(data, status) {
console.log(data);
});
结果:
array(1) {
["test"]=>
string(3) "nil"
}
12) 传0
$.post('http://xxxxx.xx/index.php', {
"test": 0
}, function(data, status) {
console.log(data);
});
结果:
array(1) {
["test"]=>
string(1) "0"
}
13) 传'null'
$.post('http://xxxxx.xx/index.php', {
"test": 'null'
}, function(data, status) {
console.log(data);
});
结果:
array(1) {
["test"]=>
string(4) "null"
}
用抓包 工具 发现
- http请求里面并不会发送
"无效的"字段——[]和{},所以不是 PHP 丢弃了,而是没收到; - 当传的值是js里的
null,会转换成空字符串,http请求里面是test=,所以PHP接收到的test是个空字符串; - http协议不能表示值是什么类型,所以PHP只能什么都当做string
总结:
- PHP对于接收到的每一个值,会转换成字符串变量
- PHP对于接收到的,之所有会接收不到是因为被一系列规则过滤掉了
以上结论是在jQ和PHP7之下验证的,其他环境不一定保证正确,之后可以试验使用CURL发送数据试试。
TODO:
- [ ] 用CURL发送POST测试
© 著作权归作者所有
共有人打赏支持
下一篇: Composer简易教程
相关文章 最新文章
前端页面是php的,页底加了js异步调用统计接口(java写的)当然传了一堆参数,频道,url等等...... 至于为啥这么做,此处省略xxxx字,我也知道这是个造轮子的事..... 目前情况是接收请求后加入队列,...
老鼠盘根
2014/03/18
193
1
有人说 : 前端传参数给后端,不管传多少个参数,都使用参数对象来接收 比如: 前端 x=12 后端就建一个A类 定义一个private int x;属性来接收 如果别的接口也需要这个参数,且还需要额外的参数,那...
_大侠__
2018/09/12
542
5
最近碰到了比较多的关于vue的eventBus的问题,之前定技术选型的时候也被问到了,vuex和eventBus的使用范围。所以简单的写一下。同时有一种特殊的实现方案。有这么几种数据传递方式,vuex、p...
前端攻城老湿
2018/12/13
0
0
jsonp确实和ajax没有半毛钱关系,只算是一种机制跨域数据获取方案或者协议。 只是说很多库(比如jquery)里面对jsonp和ajax做了一样的封装,看起来就好像jsonp是ajax的一部分一样,这好像会造...
SubinY
2016/12/26
32
0
一、背景 最近在做一些东西的时候,遇到一个需要Springmvc后台接收list类型数据的需求,几经辗转才完美解决了这个问题,今天记下来方便以后使用,也分享给需要的小伙伴们~ 二、实现方式 ...
hafiz.zhang
2016/05/16
0
0
没有更多内容
加载失败,请刷新页面
加载更多tomcat启动问题: 解决方法:tomcat bin目录下 新建setenv.sh文件 文件上加入 export CATALINA_OPTS='-Djava.awt.headless=true' 该方法对tomcat8以上有用...
west_coast
10分钟前
1
0
在微软 Build 2018 开发者大会上,.NET 团队公布了 .NET Core 的下一个主要版本 .NET Core 3.0 的规划蓝图:.NET Core 3将开始支持Windows桌面应用程序,包括Windows Form、Windows Present...
葡萄城技术团队
25分钟前
0
0
Try .NET Try .NET 是微软最近推出的在线 C# 运行环境,不用安装 Visual Studio 等,就可以直接上手写 C# 代码. 可以先进来写两行代码看看 https://try.dot.net/ 对于初学者/代码分享而言是一个...
taadis
27分钟前
21
0
PyCharm最新版本下载 JetBrains PyCharm是一种Python IDE,其带有一整套可以帮助用户在使用 Python 语言开发时提高其效率的工具。此外,该IDE提供了一些高级功能,以用于Django框架下的专业Web...
电池盒
32分钟前
0
0
没有更多内容
加载失败,请刷新页面
加载更多以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 关于在接收POST请求,Tomcat偶发性接收到的参数不全问题排查分析
- 异步接收MSMQ消息
- 如何突破商品期货Tick接收限制
- SpringMVC接收和响应json数据
- 如何使用 jq 接收 blob 数据
- 转的关于公众号接收信息的返回
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Paradigms of Artificial Intelligence Programming
Peter Norvig / Morgan Kaufmann / 1991-10-01 / USD 77.95
Paradigms of AI Programming is the first text to teach advanced Common Lisp techniques in the context of building major AI systems. By reconstructing authentic, complex AI programs using state-of-the-......一起来看看 《Paradigms of Artificial Intelligence Programming》 这本书的介绍吧!