Javascript HTTP 错误 414。请求 URL 太长
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6955302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTTP Error 414. The request URL is too long
提问by ashkufaraz
I am using ckeditor to format some data inside my textarea
我正在使用 ckeditor 来格式化我的一些数据 textarea
<textarea id="editorAbout" rows="70" cols="80" name="editorAbout"></textarea>
Now when i try to post this data using jQuery.ajax
like this,
现在,当我尝试jQuery.ajax
像这样发布这些数据时,
var about=escape( $("#editorAbout").text());
$.ajax({
type: "POST",
url: "../Allcammand.aspx?cmd=EditAboutCompany&about="+about,
type:"post",
async: false ,
success: function(response){
},
error:function(xhr, ajaxOptions, thrownError){alert(xhr.responseText); }
});
I get the error
我收到错误
HTTP Error 414. The request URL is too long.
HTTP 错误 414。请求 URL 太长。
I am getting the error here: http://iranfairco.com/example/errorLongUrl.aspx
Try clicking on the Edit Textbutton at the bottom left of that page.
我在这里收到错误:http: //iranfairco.com/example/errorLongUrl.aspx
尝试单击该页面左下角的“编辑文本”按钮。
Why is this happening? How can I solve it?
为什么会这样?我该如何解决?
回答by alnorth29
According to this questionthe maximum practical length of a URL is 2000 characters. This isn't going to be able to hold a massive Wikipedia article like you're trying to send.
根据这个问题,一个 URL 的最大实际长度是 2000 个字符。这将无法像您尝试发送的那样容纳大量的维基百科文章。
Instead of putting the data on the URL you should be putting it in the body of a POST request. You need to add a data
value to the object you're passing to the ajax function call. Like this:
您应该将数据放在 POST 请求的正文中,而不是将数据放在 URL 上。您需要向data
传递给 ajax 函数调用的对象添加一个值。像这样:
function editAbout(){
var about=escape( $("#editorAbout").text());
$.ajax({
url: "Allcammand.aspx?cmd=EditAboutCompany&idCompany="+getParam("idCompany"),
type:"post",
async: false,
data: {
about: about
},
success: function(response){
},
error:function(xhr, ajaxOptions, thrownError){alert(xhr.responseText); ShowMessage("??? ?? ?????? ??????? ????","fail");}
});
}
回答by Shadi Namrouti
In my case, there was a run-time error just before the post call. Fixing it resolved the problem.
就我而言,在 post 调用之前有一个运行时错误。修复它解决了问题。
The run-time error was trying to read $('#example').val()
where $('#example')
element does not exist (i.e. undefined
).
运行时错误是试图读取$('#example').val()
其中$('#example')
的元素不存在(即undefined
)。
I'm sure this will, certainly, help someone.
我相信这肯定会帮助某人。
回答by usefulBee
In my case, the error was raised even though I was using 'POST' and the call to the server was successful. It turned to be that I was missing the dataType attribute...strange but now it works
就我而言,即使我使用的是“POST”并且对服务器的调用成功,也会引发错误。原来是我缺少 dataType 属性......奇怪,但现在它可以工作了
return $.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: JSON.stringify(data)
})