Reputation: 8071
Greetings Everyone
I am using the following code to send data to update to a php file. The problem is I get a Request Too Long issue. I have used the 'POST' method I believe if thats the right way. Yes the data I am sending is quiet huge. So what can I do?
var link = 'updateFirstPost.php?post_id='+id+'&first_post='+encodeURIComponent(text);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
var xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
refreshPost(div_post, thread_id , id);
}
}
xmlhttp.open("POST",link,true);
xmlhttp.send();
The problem is I get a Request Too Long issue. I have used the 'POST' method I believe if thats the right way. So what can I do?
Upvotes: 2
Views: 3218
Reputation: 449623
You are putting the data into the URL, which will always cause them to be sent as GET data. GET requests have natural length limitations on both the server's and the browser's side.
To send the data through POST, you need to put the parameters like so:
var params = 'first_post='+encodeURIComponent(text);
....
http.send(params);
(stolen from here)
If this is not for learning purposes, consider using a JS framework like jQuery. It makes stuff like this much, much easier and less code-intensive.
Upvotes: 5