Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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
Javascript 将字节数组从代码隐藏发送到ajax调用_Javascript_C#_Asp.net_.net_Webmethod - Fatal编程技术网

Javascript 将字节数组从代码隐藏发送到ajax调用

Javascript 将字节数组从代码隐藏发送到ajax调用,javascript,c#,asp.net,.net,webmethod,Javascript,C#,Asp.net,.net,Webmethod,我有一个web方法,我将HTML转换为PDF,然后将其保存到本地文件夹,我希望用户下载该文件而无需发回帖子,因此我尝试在web方法中进行AJAX post调用,以获取字节数组,然后将其转换为PDF,问题是我得到一个错误500: {Message: "There was an error processing the request.", StackTrace: "", ExceptionType: ""} 虽然我知道web方法触发,因为当放置断点时它停止在那里,实际上在返回之前我可以看到二进制

我有一个web方法,我将HTML转换为PDF,然后将其保存到本地文件夹,我希望用户下载该文件而无需发回帖子,因此我尝试在web方法中进行AJAX post调用,以获取字节数组,然后将其转换为PDF,问题是我得到一个错误500:

{Message: "There was an error processing the request.", StackTrace: "", ExceptionType: ""}
虽然我知道web方法触发,因为当放置断点时它停止在那里,实际上在返回之前我可以看到二进制数组以及文件夹中创建的文件,但我仍然得到错误按摩,下面是我的代码:

C#:

JS:

有什么想法吗


谢谢

我通过将此添加到我的web.config中来解决此问题:

 <system.web.extensions>
    <scripting>
      <webServices>
        <!-- Update this value to change the value to a larger value that can accommodate your JSON Strings -->
        <jsonSerialization maxJsonLength="86753090" />
      </webServices>
    </scripting>
  </system.web.extensions>


通过这种方式,您可以返回最大字节数组,并且可以转换为PDF格式并下载数据类型。我认为,数据类型不应该是“json”。你可能想使用另一个api。也许?我肯定这个方法会起作用,因为这实际上是从一个方法复制粘贴的,我将word文件转换成字节数组,不同的是,在这种情况下,文件位于一个文件夹中,我的另一个方法的文件位于数据库中,这就是为什么我不知道为什么这个特别不起作用。有趣的是,它似乎不应该起作用。
$.ajax({
    type: "POST",
    url: "dashboard.aspx/getfile",
    contentType: "application/json; charset=utf-8",
    data: "{'one':\"" + one+ "\", 'two':\"" + two + "\" }",
    dataType: "json",
    processData: false,
    success: function (data) {
        data = data.d;

        var byteArray = new Uint8Array(data);
        var a = window.document.createElement('a');

        a.href = window.URL.createObjectURL(new Blob([byteArray], { type: 'application/pdf' }));

        a.download = "Dashboard";

        document.body.appendChild(a)
        a.click();
        document.body.removeChild(a)
    }
});
 <system.web.extensions>
    <scripting>
      <webServices>
        <!-- Update this value to change the value to a larger value that can accommodate your JSON Strings -->
        <jsonSerialization maxJsonLength="86753090" />
      </webServices>
    </scripting>
  </system.web.extensions>
 var jsonResult = Json(model, JsonRequestBehavior.AllowGet);
            jsonResult.MaxJsonLength = int.MaxValue;
            return jsonResult;