I have this form which cotains 2 input
elements and 1 textarea
element.
The textarea is not limited and can have really big content. I want to send that data to backend where it will be processed and written in database. How I can achive this?
This is code I have so far
<script type="text/javascript">
var form = document.getElementById('blogs_form');
form.addEventListener('submit', function(event) {
event.preventDefault();
var quote = document.getElementById("blog_title").value;
var author = document.getElementById("author").value;
var text = document.getElementById("text").value;
var data = "blog_title=" + quote + "&author=" + author + "&text=" + text;
console.log(data)
var xhr = new XMLHttpRequest();
var url = "http://localhost/backend/blogs.php?" + data;
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "none");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = xhr.responseText;
if(response !== 'success') {
Swal.fire({
type: 'error',
text: response,
})
} else {
Swal.fire({
type: 'success',
text: 'Blog recorded in database',
})
}
}
};
xhr.send();
})
</script>
I am sending it by creating XMLHttpRequest()
with method POST
as you can see in code above.
Problem with this is when I write about 8000 characters it breaks and I get 414
response. Which means that URI is too long.
Is there any way to send as much data as I want? It will be always just text data.
Also. Could it be server side problem? That it has some kind of limits? And if so is there a way to avoid this?