在我的应用程序中,我通过 jquery ajax 将网页的 html 发送回服务器(因为我需要在服务器中存储此页面的副本)。代码是这样的
$(document).ready(function () {
var pcontent = document.body.innerHTML;
var url = new URI().addQuery("pcontent", pcontent);
$.ajax({
url: url,
type: "GET",
success: function (data) {
alert(data.html());
},
complete: function () {
alert(1);
},
error: function(jqXHR, error, errorThrown) {
if (jqXHR.status) {
alert(jqXHR.responseText);
}
else {
alert("Something went wrong");
}
}
});
return false;
});
但这会引发错误:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>Request URL Too Long</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii">
</HEAD>
<BODY>
<h2>Request URL Too Long</h2>
<hr>
<p>HTTP Error 414. The request URL is too long.</p>
</BODY>
</HTML>
有什么办法可以做到这一点?
编辑:从我从这里得到的输入我已经改变了我的代码(改变 get to post)
$(document).ready(function () {
var pcontent = document.body.innerHTML;
var url = new URI().addQuery("pcontent", pcontent);
$.ajax({
url: url, type: "POST"
, success: function (data) {
alert(data.html());
},
complete: function () {
alert(1);
},
error: function (jqXHR, error, errorThrown) {
if (jqXHR.status) {
alert(jqXHR.responseText);
} else {
alert("Something went wrong");
}
}
});
return false;
});
但仍然存在相同的错误