Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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 HTTP错误414。请求URL太长_Javascript_Asp.net Mvc_Url - Fatal编程技术网

Javascript HTTP错误414。请求URL太长

Javascript HTTP错误414。请求URL太长,javascript,asp.net-mvc,url,Javascript,Asp.net Mvc,Url,Javascript: function tableToExcel() { var calendar = document.getElementById("calendar").innerHTML; window.location.href = "/Calendar/ExportData?calendar=" + calendar; } 控制器: public ActionResult ExportData(string calendar) { s

Javascript:

function tableToExcel() {

var calendar = document.getElementById("calendar").innerHTML;

window.location.href = "/Calendar/ExportData?calendar=" + calendar;
}
控制器:

 public ActionResult ExportData(string calendar)
        {
            string headerTable = calendar;

            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + "Calendar" + ".xls;");
            Response.ContentType = "application/ms-excel";

            Response.ContentEncoding = System.Text.Encoding.Unicode; 
            Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());

            Response.Write(headerTable);
            Response.Flush();
            Response.End();

            return new EmptyResult();
        }
如果我使用window.location.href将document.getElementById(“calendar”).innerHTML发送到ExportData,我会看到下面的url异常

Request URL Too Long

HTTP Error 414. The request URL is too long.

我发送参数,但浏览器获取参数作为url为什么?为了解决这个问题,我应该做些什么呢?

MaxURL大小是2083个字符

正如@Brian所提到的,HTTP客户端(例如浏览器)可能有 它们有自己的限制,HTTP服务器将有不同的限制。 Microsoft支持人员表示“URL的最大长度为2083个字符 Internet Explorer”。IE在URL长度上存在问题

对此,您应该使用post方法,因此:

这段代码创建一个表单并将其附加到正文中并提交

function tableToExcel() {
    var calendar = document.getElementById("calendar").innerHTML;

    var form = $('<form action="ExportData" method="post"><input type="text" name="calendar" /></form>')

    form.find('input').val(calendar);

    form.appendTo('body').submit();
}
[HttpPost]
public ActionResult ExportData(string calendar)