将formData发布到服务器端操作方法时遇到一些问题。因为ajax调用不会将文件发送到服务器,所以我必须手动将文件上传器数据添加到formData中 调用服务器方法
是不可能的[WebMethod]
public HttpPostedFileBase Name(HttpPostedFileBase file)
{
string ret = "test";
return file;
}
客户端错误没有 我编写了jQuery函数,需要使用ajax调用将表单数据发布到服务器。 这是我的剧本:
data.append(self.idFileInput, file[f]);
$.ajax({
type: "POST",
url: "/AddContract.aspx/Name",
data: data,
dataType: 'json',
contentType: false,
processData: false,
success: function (data) {
}
});
任何提示,链接或代码示例都很有用 提前谢谢!
答案 0 :(得分:1)
尝试使用contentType:'application / json;字符集= UTF-8' ,
$.ajax({
type: "POST",
url: "AddContract.aspx/Name",
data: { field1: self.idFileInput, field2 : file[f]} ,
dataType: 'json',//Remove this line this line is causing issue.
contentType: 'application/json; charset=utf-8',
processData: false,
success: function (data) {
}
});
答案 1 :(得分:0)