【发布时间】:2011-07-16 04:50:48
【问题描述】:
我在 Javascript 中有一个对象,我正在尝试将 AJAX POST 发送到 PHP 脚本。在 jQuery 1.4.1 中一切正常,但现在在 1.4.4 或更高版本中,所有空数组或空对象都作为不正确的 string(0) 到达。
JS:
$(document).ready(function() {
var obj = {};
obj.one = [];
obj.two = {};
obj.three = [];
obj.three.push('one');
obj.three.push('two');
obj.three.push('three');
obj.four = "onetwothree";
$.ajax({
type: 'POST',
url: 'ajax.php',
data: obj,
success: function(data) {
alert(data);
},
});
});
PHP:
<?php
var_dump($_POST);
?>
回复:
array(4) {
["one"]=> string(0) ""
["two"]=> string(0) ""
["three"]=> array(3) {
[0]=> string(3) "one"
[1]=> string(3) "two"
[2]=> string(5) "three"
}
["four"]=> string(11) "onetwothree"
}
在 1.4.1 版本中,它不会发送 ["one"] 或 ["two"],但现在在较新的版本中,它作为字符串到达的事实会影响整个应用程序。有什么办法可以让空数组 ([]) 作为空数组 ([]) 到达 PHP 并与 JavaScript 对象相同?
【问题讨论】:
-
嗨。你找到解决这个问题的方法了吗?我也对这个感兴趣。在我看到你的帖子之前,我已经发布了this。
标签: javascript jquery ajax json post