我可以发送序列化的数据以及通过JQuery的$。员额其他变量? [英] can I send serialized data along with other variables through JQuery $.post?
问题描述
因此可以说,我想从根本上做到这一点:
$。员额(
search_item.php,
{
serialzed_data,
保存:form.save.value,
is_correct:form.is_correct.value,
等等...
}
)
什么是正确的语法,这样做呢?
千恩万谢,
修改以指定:
可以说我有这样的:
$。员额(
search_item.php,
{
检查:post_data,
'选项[]':选项,
保存:form.save.value,
项目:form.item.value,
名称:form.i_name.value,
说明:form.i_desc.value,
文本:form.i_text.value
},
功能(输出){
$('#RETURN2)HTML(输出).show();
});
现在,目前的.POST我想要将它添加到它,并张贴在一起:
VAR serialized_data = $('输入[名字^ =检查]:选中)序列化()。
我该怎么办呢?
修改最新尝试:
VAR post_data = $('输入[名字^ =检查]:选中)序列化()。
VAR数据= $ .extend({},post_data,{
'选项[]':选项,保存:form.save.value,
项目:form.item.value,
名称:form.i_name.value,
说明:form.i_desc.value,
文本:form.i_text.value
});
.post的$('search_item.php',数据,
功能(输出){
$('#RETURN2)HTML(输出).show();
});
您想使用 serializeArray 代替( .serialize
轮番元素转换为字符串,而不是一个数组),像这样:
$。员额('search_item.php',{
serializedData:$('输入[名字^ =检查]:选中)serializeArray()。
extraVar:值
},
功能(输出){
$('#RETURN2)HTML(输出).show();
});
在 serializedData code>将是一个数组,而不是一个'词典',所以你必须要分析它的另一端。
其实... .serialize
将工作就好了。如果你使用PHP的后端,你只需要通过的 parse_str 。
也可以使键/值对一个实际的对象,并去与菲尔的解决方案使用此。
so lets say I wanted to essentially do this:
$.post(
'search_item.php',
{
serialzed_data,
save: form.save.value,
is_correct: form.is_correct.value ,
etc...
}
)
What is the correct syntax to do so?
many thanks,
EDIT to specify:
lets say I have this:
$.post(
'search_item.php',
{
'checks':post_data,
'option[]':option,
save: form.save.value,
item: form.item.value,
name: form.i_name.value,
desc: form.i_desc.value,
text: form.i_text.value
},
function(output) {
$('#return2').html(output).show();
});
now with that current .post I want to add this to it and post them together:
var serialized_data = $('input[name^="checks"]:checked').serialize();
can I do it?
EDIT latest attempt:
var post_data = $('input[name^="checks"]:checked').serialize();
var data = $.extend({}, post_data, {
'option[]':option, save: form.save.value,
item: form.item.value,
name: form.i_name.value,
desc: form.i_desc.value,
text: form.i_text.value
});
$.post('search_item.php', data ,
function(output) {
$('#return2').html(output).show();
});
You want to use serializeArray instead (.serialize
turns the elements into a string, not an array) like so:
$.post('search_item.php', {
serializedData: $('input[name^="checks"]:checked').serializeArray(),
extraVar: value
},
function(output) {
$('#return2').html(output).show();
});
The serializedData
will be an array, not a 'dictionary', so you'll have to parse it out on the other end.
Actually... .serialize
would work just fine too. If you're using PHP on the backend, you'd just have to pass it through parse_str.
or you can make an actual object of key/value pairs and go with Phil's solution using this.
这篇关于我可以发送序列化的数据以及通过JQuery的$。员额其他变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!