Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C#返回HttpResponseMessage的WebApi的ajax调用中,数据类型应该是什么_C#_Ajax_File_Asp.net Web Api - Fatal编程技术网

在C#返回HttpResponseMessage的WebApi的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_

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_error!=未定义)callback_error()仍然存在的问题是samechange
success: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();
             }
         });