我试图使用FORMDATA到上传的图片传+两个额外的参数使用FORMDATA方法从我的Ajax方法,我的Web服务的WebMethod这里:传递更多然后1点的值通过Ajax
var formData = new FormData();
formData.append('file', $('#photo')[0].files[0]);
formData.append('u', "test");
formData.append('s', "Testing");
我的Ajax调用概述如下所示:
$.ajax({
url: "/admin/WebService/test.asmx/UploadImage",
type: "POST",
processData: false,
contentType: false,
data: formData,
success: function (response) {
console.log(response);
},
error: function (er) {
alert(er);
}
});
调用该的WebMethod:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string UploadImage()
{
if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
{
var t= System.Web.HttpContext.Current.Request.Files["s"];
var c= System.Web.HttpContext.Current.Request.Files["u"];
var p = System.Web.HttpContext.Current.Request.Files["file"];
}
else
{
return "Error";
}
return "Error";
}
的问题,我'm have是参数'u'和's'在引用文件时我能够得到它的值。
在搜索网页的同时,我在印象之下可以指定使用此方法时需要的许多键/值,除非我误导了信息?有人可以请说明为什么这两个参数为空?提前致谢。
也为我工作,谢谢 –