-2
我有一个ASP.NET c#
页面,该页面将以JSON格式发布带有AJAX的表单信息。 此信息包括文本Texboxes
和值Dropdownlists
等通过AJAX发送文件以及JSON信息
此外我也需要发送文件。
我曾尝试下面的代码,它工作正常:
$(".popup-content input:text,.popup-content textarea").each(function() { // Fill object by inputs
objInputs[$(this).attr("name")] = $(this).val();
});
$.ajax({ //Post information
type: "POST",
url: "myAjax.aspx",
data: { func: "Create", information: JSON.stringify(objInputs) /* Convert object to JSON string */ },
success: function (data) { // if sending was successful try to send file
var files = $("#fileImage").get(0).files; //get files form uploadfile
if (files.length > 0) {
var data = new FormData();
data.append(files[0].filename, files[0]);
$.ajax({ //Send file
type: "POST",
url: "Handler1.ashx",
contentType: false,
processData: false,
data: data,
success: function (data) {
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + " " + thrownError);
},
});
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + " " + thrownError);
},
});
但现在我想知道是否有办法把我的文件,我的JSON一起?
你尝试过这么远吗?你使用ASP.NET创建什么样的应用程序? Web窗体? MVC? – Guanxi
@关西我没有尝试任何东西。然后使用ASP.NET WebForms –
然后Google出如何上传文件,如果遇到任何问题,请在此处提问。我相信你可以很容易地在谷歌上找到关于文件上传的很多东西。 – Guanxi