douli2876
2015-03-07 11:25
浏览 67

使用jQuery和Ajax发送输入数组

I am trying to send a form field array through my form but am unsuccessfull :-/

I have a hidden field, generated from jQuery, looking like this:

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

This is generated for each file uploaded to this post. When I then submit the form I do not get anything through the "pimage" form submission. All other fields return a value?!? Below is the jQuery Ajax I am trying to use:

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  });

What am I doing wrong. Any help is appreciated.

Thanks in advance :-)

图片转代码服务由CSDN问答提供 功能建议

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

我有一个隐藏字段,由jQuery生成,如下所示:

  $(“。imghidden”)。html('&lt; input type =“ 隐藏“name =”pimage []“value =”'+ data.imgname +'“&gt;'); 
   
 
 

这是为上传到此的每个文件生成的 帖子。 当我提交表格时,我没有通过“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()
 
 //使用post 
var posts = $发送数据。  post(“data / mod / projects.php”,{createnew:true,cat:category,newcat:newcategory,ti:title,sti:subtitle,con:content,pimg:pimage}); 
  <  / pre> 
 
 

我做错了什么。 任何帮助表示赞赏。

提前致谢: - )

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dpbe81245 2015-03-07 11:29
    已采纳

    Your jQuery selector is looking for an input with name pimage... which doesn't exist. I haven't tested it, but it looks like your jQuery selector should be looking for pimage[] instead.

    e.g.

    pimage = $form.find( "input[name='pimage[]']" ).val()
    
    点赞 评论
  • drh78568 2015-03-07 11:30

    You are trying to find a selector that doesn't exist. Try

    $form.find( "input[name^='pimage']" ).val()
    
    点赞 评论

相关推荐 更多相似问题