繁体   English   中英

使用jQuery和Ajax发送输入数组

[英]Sending input array with jQuery and Ajax

我正在尝试通过表单发送表单字段数组,但未成功:-/

我有一个从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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM