I am using some ajax request to access to php file. It's working perfectly exept one part. When I am getting the $_POST value of one of my variable, it crops the end of the word.
$.ajax({
type: 'post',
url: 'https://myadress.com',
data: {
workout: JSON.stringify(workout),
username: localStorage.getItem('username'),
workout_name: $('#name').val().toString(),
},
success: function (data) {
alert(data);
},
});
If i alert workout_name before sending it, it displays "test" but when i echo it from my php file, it displays "te". I am wondering why it's doing that, i can't fix it. I was thinking maybe the size of my other variable are too big... Here is my php code:
` if(isset($_POST['username']) && isset($_POST['workout_name']) && isset($_POST['workout'])) {
$workout_name = $_POST['workout_name'];
echo $workout_name;
$username = $_POST['username'];
$workout = json_decode($_POST['workout']);
}`
Thank you for your answer.
Edit: Thanks to the answer, it's working now. I just need to do :
workout_name: encodeURIComponent($('#name').val())
in my js file and when I retrieve the data in the php file I use :
urldecode($_POST['workout_name']);