I am trying to create something like system of posts, which could allow users to write as much as they want in each post. But I have a problem with transferring a long sting through AJAX. It always says that (the length of the link is too large) so I tried to divide my string into some segments and transfer them one by one and write them into a text file (I don't want to use database to store what users will write) by using PHP (fopen) function with (a) flag to continue writing like below
fopen($directory,"a")
also, I used (encodeURIComponent) with each part of the long string to remain (\n, spaces, ... etc.), but what I got as results was like this
e.g. what I wrote
bla bla bla bla bla bla bla 
what I got
bla bla bla SSbla bla bla b
how to solve this problem ??
my JS code where (d) is the string
function sendDetails(t){
    t = encodeURIComponent(t);
    var x = new XMLHttpRequest();
    x.open("POST","src/writeDetails.php?t="+t,true);
    x.send();
}
function writeDetails(d){
    var r = Math.floor(d.length / 1000);
    var m = d.length % 1000;
    for(i=0;i<r;i++){
        var p = d.slice(i*1000,i*1000+999);
        sendDetails(p);
    }
    if(i > 0){
        sendDetails(d.slice(i*1000,i*1000+m));
    }else{
        sendDetails(d.slice(0,m))
    }
}
my PHP code
$t = $_REQUEST['t'];
$f = fopen($fileLink,"a");
fwrite($f,$t);
fclose($f);
 
     
     
    