使用jQuery和Ajax发送输入数组

Man*_*nsa 0 javascript php forms ajax jquery

我试图通过我的表单发送一个表单字段数组但是不成功: - /

我有一个隐藏字段,从jQuery生成,看起来像这样:

$(".imghidden").html('<input type="hidden" name="pimage[]"  value="'+data.imgname+'">');
Run Code Online (Sandbox Code Playgroud)

这是为上传到此帖子的每个文件生成的.当我提交表格时,我没有通过"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  });
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么.任何帮助表示赞赏.

提前致谢 :-)

Edd*_*tle 5

您的jQuery选择器正在查找名称为pimage... 的输入,该输入不存在.我没有测试它,但看起来你的jQuery选择器应该寻找pimage[].

例如

pimage = $form.find( "input[name='pimage[]']" ).val()
Run Code Online (Sandbox Code Playgroud)