Php jquery序列化和$.post并在服务器端接收不完整的数组
jquery:Php jquery序列化和$.post并在服务器端接收不完整的数组,php,jquery,serialization,Php,Jquery,Serialization,jquery: $("#btnSaveForm").click(function(){ ... $.post('../optional/setup/processItemcn.php', $("#FormTemplate").serialize(), function(data) { alert(data); }); ... }); 具有以下格式的php: <form id="FormTemplate" class="FormTemplate"> <input
$("#btnSaveForm").click(function(){
...
$.post('../optional/setup/processItemcn.php', $("#FormTemplate").serialize(), function(data) {
alert(data);
});
...
});
具有以下格式的php:
<form id="FormTemplate" class="FormTemplate">
<input type="text" name="kode_item[]" value="1" />
<input type="text" name="kode_item[]" value="2" />
<input type="text" name="kode_item[]" value="3" />
.
.
<input type="text" name="kode_item[]" value="197" />
</form>
我正在尝试使用jquery post和serialize将表单中的所有数组数据发送到服务器端。
我有kode_item=197个项目的total items数组,但在将其发送到服务器端之后,我检查并从服务器端回显$count=167个项目的结果。这就是为什么我不能更新与kode_item>167相关的数据,因为它不会在服务器端处理。有人有什么想法吗?尝试检查php.ini中的设置是否正确
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
解决方案来自我的网络主机技术人员 从表单发送到服务器端的数组数据太长,然后。。限制将要发送的阵列数据 这种方法对我有用。将这两行添加到php.ini:
suhosin.post.max_vars = 1500
suhosin.request.max_vars = 1500
我也遇到了这个问题,但没有找到解决方案,在阅读jQuery文档后,我有了一个想法 您可以使用
.serializeArray()
,而不只是使用.serialize()
和使用php.ini文件。下面是我在项目中使用的代码
jQuery('.modal').on('click','.saveFeature',function(){
var form = jQuery('#featureForm').serializeArray();
jQuery.ajaxSetup({
data:{
csrf_name:jQuery('input[name="csrf_name"]').val()
}
});
var url = "<?php echo 'product/features/'.$pid;?>";
jQuery.post(url,{form}, function(msg){
alert(msg);
} );
});
在后端处理post数据,我使用CodeIgniter框架。以key=>value
格式组织post数据,以便于存储数据
$arry = $this->input->post('form');
$post = [];
//check if this is not empty and is array
if(!empty($arry) && is_array($arry)){
//iterate over post data and organize array in key value format.
foreach($arry as $ar)
{
$post[$ar['name']] = $ar['value'];
}
}
$data = [
'pid' => $pid,
'title' => $post['title'],
'icon' => $post['title_icon'],
'icon_color' => $post['icon_color'],
'icon_bg_color' => $post['icon_bg_color'],
'description' => $post['description'],
'box_bg_color' => $post['box_bg_color'],
'box_bttm_color' => $post['box_bttm_bg'],
];
$this->db->insert(TBL_PRODUCT_FEATURES, $data);
如果我错了,请纠正我;我刚刚分享了我解决这个问题的想法。请显示
print\r($ID)
.alert($(“#FormTemplate input[type=text]”)的输出。length);代码中是否有空字段(无值)?代码使用200个条目进行测试,也通过发送空值进行测试,但计数总是正确的。您必须在某个地方漏掉拼写。。深究-inside@strprint_r($ID)的结果是:数组([0]=>1[1]=>2[2]=>3…[166]=>167)检查我的php.inipost_max_size=80M
已经更改为8M,然后重新启动apache服务,没有任何更改……并且……还尝试更改max_execution\u time=1000
但仍然没有更改。。。
Array
(
[0] => Array
(
[name] => csrf_name
[value] => 3802b11296d42e602533bf266bb800bd
)
[1] => Array
(
[name] => title
[value] => kjhkjh
)
[2] => Array
(
[name] => title_icon
[value] => fa fa-heart
)
[3] => Array
(
[name] => icon_color
[value] => #a81616
)
[4] => Array
(
[name] => icon_bg_color
[value] => #662f2f
)
[5] => Array
(
[name] => description
[value] => testb
)
[6] => Array
(
[name] => box_bg_color
[value] => #bd2222
)
[7] => Array
(
[name] => box_bttm_bg
[value] => #a61e1e
)
)
$arry = $this->input->post('form');
$post = [];
//check if this is not empty and is array
if(!empty($arry) && is_array($arry)){
//iterate over post data and organize array in key value format.
foreach($arry as $ar)
{
$post[$ar['name']] = $ar['value'];
}
}
$data = [
'pid' => $pid,
'title' => $post['title'],
'icon' => $post['title_icon'],
'icon_color' => $post['icon_color'],
'icon_bg_color' => $post['icon_bg_color'],
'description' => $post['description'],
'box_bg_color' => $post['box_bg_color'],
'box_bttm_color' => $post['box_bttm_bg'],
];
$this->db->insert(TBL_PRODUCT_FEATURES, $data);