在C#返回HttpResponseMessage的WebApi的ajax调用中,数据类型应该是什么
C中的WebApi解析# Web Api返回正确的响应,但ajax调用返回错误而不是成功。帮我解决这个问题在C#返回HttpResponseMessage的WebApi的ajax调用中,数据类型应该是什么,c#,ajax,file,asp.net-web-api,C#,Ajax,File,Asp.net Web Api,C中的WebApi解析# Web Api返回正确的响应,但ajax调用返回错误而不是成功。帮我解决这个问题 在ajax调用->中,我尝试使用value=application/octet stream的数据类型,但这也不起作用。什么是callback\u success我怀疑如果您解决了问题,您的问题就会消失。@Seabizkit即使在成功if(callback\u success!=未定义)callback\u success(result)中注释了这两个if条件和错误if(callback_
在ajax调用->中,我尝试使用value=application/octet stream的数据类型,但这也不起作用。什么是
callback\u success
我怀疑如果您解决了问题,您的问题就会消失。@Seabizkit即使在成功if(callback\u success!=未定义)callback\u success(result)中注释了这两个if条件代码>和错误if(callback_error!=未定义)callback_error()代码>仍然存在的问题是samechangesuccess:function(result){…}
到success:function(result){debugger;}
在浏览器上打开F12进行调试窗口并检查结果。当firedwhat error(firedwhat error)出现时,请检查网络选项卡以及Web浏览器中调试器工具中服务器的响应。看看回复是否符合您的期望
public HttpResponseMessage DownloadFilesDirect(List<string> filesId)
{
var response = new HttpResponseMessage();
//code to extract file
if (filesList == null)
{
return response = new HttpResponseMessage(HttpStatusCode.Gone);
}
else
{
var file = filesList[0].File;
response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(file.Open(FileMode.Open, FileAccess.Read));
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition.FileName = file.Name;
}
return response;
}
$.ajax({
url: urlforwebapi,
type: CONST_HTTP_POST,
//xhrFields: { withCredentials: true },
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data),
success: function (result) {
if (callback_success != undefined) callback_success(result);
},
error: function () {
if (callback_error != undefined) callback_error();
}
});