我正在尝试通过我的表单发送表单字段数组,但没有成功:-/
我有一个隐藏字段,由jQuery生成,如下所示:
$(".imghidden").html('<input type="hidden" name="pimage[]" value="'+data.imgname+'">');
这是为上传到此帖子的每个文件生成的。当我提交表格时,我没有通过"pimage"表格提交得到任何东西。所有其他字段都返回一个值?!?下面是我尝试使用的jQuery Ajax:
var $form = $( this ),
category = $form.find( "select[name='category']" ).val(),
newcategory = $form.find( "input[name='newcategory']" ).val(),
title = $form.find( "input[name='title']" ).val(),
subtitle = $form.find( "input[name='subtitle']" ).val(),
content = $form.find( "textarea[name='content']" ).val(),
pimage = $form.find( "input[name='pimage']" ).val()
// Send the data using post
var posting = $.post( "data/mod/projects.php", { createnew: true, cat: category, newcat: newcategory, ti: title, sti: subtitle, con: content, pimg: pimage });
我做错了什么。任何帮助,不胜感激。
提前感谢:-)
您的 jQuery 选择器正在寻找名称为 pimage
的输入...不存在。我还没有测试过它,但看起来你的jQuery选择器应该寻找pimage[]
。
例如
pimage = $form.find( "input[name='pimage[]']" ).val()
您正在尝试查找不存在的选择器。尝试
$form.find( "input[name^='pimage']" ).val()