Reputation: 1669
I need to pass huge data to the controller. I have used XmlHttpRequest
.
I have written the code like:
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("POST", "/Home/Content", true);
xmlhttp.send("content=" + data);
And the ActionResult
will look like
[HttpPost]
public ActionResult(string content)
{
return Json("suc", JsonRequestBehavior.AllowGet);
}
The data will be like
UklGRipkAABXRUJQVlA4[...huge piece of data...]kxgTrTkKyKe6xap+GYnY93Kj
But it is not passing to the controller. It is showing that data is too long. How can I get rid of this?
Upvotes: 2
Views: 651
Reputation: 115920
Send the data in the POST body, by passing it as an argument to send
:
xmlhttp.open("POST", "/Home/Content", true);
xmlhttp.send("content=" + data);
Then, on the server, read the content
parameter of the POST data.
Upvotes: 1