这是我的 javascript 代码:
var fileURL = "file://" + mFileListURL[0].fullPath;
var options = new FileUploadOptions();
options.fileKey = "recFile";
var imagefilename = Number(new Date()) + ".jpg";
options.fileName = imagefilename;
options.mimeType = "image/jpeg";
var params = new Object();
options.params = params;
var ft = new FileTransfer();
ft.upload(fileURL,"http://mywebserver/UploadFoto.asmx/SaveImage",
function(r) {
alert("It's OK!");
alert("Response = " + r.response);
}, function(error) {
alert("An error has occurred: Code = "
+ error.code);
}, options);
这个服务器端代码:
[WebMethod]
[GenerateScriptType(typeof(String))]
[ScriptMethod]
public String SaveImage()
{
HttpContext context = HttpContext.Current;
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
foreach (string key in files)
{
HttpPostedFile file = files[key];
string fileName = file.FileName;
if (fileName != null && fileName != "")
{
String fileStored = System.IO.Path.Combine(context.Server.MapPath("~/public/"), fileName);
file.SaveAs(fileStored);
}
}
}
return "Filestored OK";
}
现在,图像上传完成,但我没有收到返回的字符串,没有来自服务器的响应,也没有错误代码。我也使用了 Json 响应,但什么也没有(图片上传,没有响应,没有返回字符串)。怎么了?
谢谢。国际文凭