header('Access-Control-Allow-Origin:*'); var_dump($_POST); exit;
$.post('http://xxxxx.xx/index.php', { "test": null }, function(data, status) { console.log(data); });
结果:php
array(1) { ["test"]=> string(0) "" }
代码:前端
$.post('http://xxxxx.xx/index.php', { "test": '' }, function(data, status) { console.log(data); });
结果:工具
array(1) { ["test"]=> string(0) "" }
$.post('http://xxxxx.xx/index.php', { "test": '[]' }, function(data, status) { console.log(data); });
结果:post
array(1) { ["test"]=> string(2) "[]" }
$.post('http://xxxxx.xx/index.php', { "test": [] }, function(data, status) { console.log(data); });
结果:测试
array(0) { }
$.post('http://xxxxx.xx/index.php', { "test": [], "test2": [] }, function(data, status) { console.log(data); });
结果:code
array(0) { }
$.post('http://xxxxx.xx/index.php', { "test": {} }, function(data, status) { console.log(data); });
结果:对象
array(0) { }
$.post('http://xxxxx.xx/index.php', { "test": {}, "test2": {} }, function(data, status) { console.log(data); });
结果:字符串
array(0) { }
$.post('http://xxxxx.xx/index.php', { "test": {}, "test2": {"a": 1} }, function(data, status) { console.log(data); });
结果:string
array(1) { ["test2"]=> array(1) { ["a"]=> string(1) "1" } }
$.post('http://xxxxx.xx/index.php', { "test": [{}] }, function(data, status) { console.log(data); });
结果:it
array(0) { }
$.post('http://xxxxx.xx/index.php', { "test": [[{}]] }, function(data, status) { console.log(data); });
结果:
array(0) { }
$.post('http://xxxxx.xx/index.php', { "test": 'nil' }, function(data, status) { console.log(data); });
结果:
array(1) { ["test"]=> string(3) "nil" }
$.post('http://xxxxx.xx/index.php', { "test": 0 }, function(data, status) { console.log(data); });
结果:
array(1) { ["test"]=> string(1) "0" }
$.post('http://xxxxx.xx/index.php', { "test": 'null' }, function(data, status) { console.log(data); });
结果:
array(1) { ["test"]=> string(4) "null" }
用抓包工具发现
"无效的"
字段——[]和{},因此不是PHP丢弃了,而是没收到;null
,会转换成空字符串,http请求里面是test=
,因此PHP接收到的test是个空字符串;以上结论是在jQ和PHP7之下验证的,其余环境不必定保证正确,以后能够试验使用CURL发送数据试试。