我如何发送图像+一些json对象数据到ashx处理程序?
在jquery ajax post中有可能吗?

像这样:

         var fileUpload = $("#image").get(0);
            var files = fileUpload.files;

            var imag = new FormData();
            for (var i = 0; i < files.length; i++) {
                imag.append(files[i].name, files[i]);
            }



            $.ajax({
                type: "POST",
                url: "../Scripts/uploadify/UploadHandler.ashx",
                contentType: false,
                processData: false,
                data: "image=" + imag + "&Data=" + JSON.stringify({ objEnt: args }),
                success: function(){

                }

            });


我们可以这样吗?

最佳答案

将所有文件追加到创建的FormData对象后,只需对json数据imag.append('Data', JSON.stringify({ objEnt: args }))进行另一个追加。然后将ajax请求的data:设置为imag

var fileUpload = $("#image").get(0);
var files = fileUpload.files;

var imag = new FormData();
for (var i = 0; i < files.length; i++) {
    imag.append(files[i].name, files[i]);
}

imag.append('Data', JSON.stringify({ objEnt: args }));


$.ajax({
    type: "POST",
    url: "../Scripts/uploadify/UploadHandler.ashx",
    contentType: false,
    processData: false,
    data: imag,
    success: function(){

    }

});

07-26 01:45