Javascript 如何将java脚本中的文件数组和其他string/int变量一起传递给php

Javascript 如何将java脚本中的文件数组和其他string/int变量一起传递给php,javascript,jquery,ajax,Javascript,Jquery,Ajax,我想传递imageArray[]以及一个变量trackNo。imageArray[]我可以毫无问题地通过它。我只是不确定如何在FormData()中附加/包含其他变量 在网上,我只看到人们只将一个文件数组传递给一个php文件,而从不传递其他信息的例子 $('#ad_post_btn').click(function () { ad_errmsg = ""; imageList = myImageList(); //my array of images imageList[]

我想传递
imageArray[]
以及一个变量
trackNo
imageArray[]
我可以毫无问题地通过它。我只是不确定如何在
FormData()中附加/包含其他变量

在网上,我只看到人们只将一个文件数组传递给一个php文件,而从不传递其他信息的例子

$('#ad_post_btn').click(function () {
    ad_errmsg = "";

    imageList = myImageList(); //my array of images imageList[]

    console.log(imageList); //display files in imageList[]

    var trackNo = Math.round(Math.random() * (100000 - 1) + 1); // random number

    console.log(trackNo); // shows the random generated number

    var data = new FormData(); 
    var dataString = 'trackno=' + trackNo; //the variable a want to pass along with the array

    for (var i = 0; i < imageList.length; i++) {
        data.append('images[]', imageList[i]); //where I store my image files, work fine
    }

    $.ajax({
        url: 'uploadimage.php',
        type: 'post',
        data: data,
        contentType: false,
        processData: false,
        success: function (data) {
            console.log(data);

        }
    });
感谢您花时间提供数据。附加('trackno',trackno)

您可以将其放在for循环之前或之后

.append('key',value)
将允许您不断添加更多字段


解决方案:

data.append("key", value);
来源:


我们可以看到myFileList()函数吗?data:data+“&dataString=dataString”,您可以这样传递too@MarkOverton
函数myImageList(){return imageList;}
不管怎样,我的问题已经解决了这很好,谢谢
data.append("key", value);