简体   繁体   English

在ajax中发送文件和多个字段值

[英]Sending file and multiple field values in ajax

Currently using this: 当前正在使用此:

    function acceptimage() {
      var data = new FormData();
      jQuery.each($('#uploadImage')[0].files, function(i, file) {
          data.append('uploadImage-'+i, file);
      });

      $.ajax({
        url: 'upload.php',
        data: data,
        cache: false,
        contentType: false,
        processData: false,
        type: 'POST',
        success: function(data){
          alert(data);
          popup('popUpDiv');
          ias.cancelSelection();
          ias.update();
        }
      });
    };

And it's sending my file perfectly, but I need to send 4 field values along with it. 它完美地发送了我的文件,但是我需要一起发送4个字段值。 Could anyone let me know how I post: 谁能让我知道我的发布方式:

<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />

Along with the file? 随文件一起? Many thanks 非常感谢

function acceptimage() {
    var data = new FormData();
    jQuery.each($('#uploadImage')[0].files, function(i, file) {
    data.append('uploadImage-'+i, file);
    data.append('x', $("#x").val());
    data.append('y', $("#y").val());
    data.append('w', $("#w").val());
    data.append('h', $("#h").val());
});

$.ajax({
    url: 'upload.php',
    data: data,
    cache: false,
    contentType: false,
    processData: false,
    type: 'POST',
    success: function(data){
    alert(data);
    popup('popUpDiv');
    ias.cancelSelection();
    ias.update();
}
}); 
};

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

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