So,I send an array of inputs:
<input type="text" placeholder="Question" name="question[]" value="" />
<input type="text" placeholder="Question" name="question[]" value="" />
with this Jquery code:
$.post("function.php",{Question:$("[name^='question']").serialize()},function(data){
$("#construct").append(data);
alert('done');
});
but when I try to echo
the variables of array it prints incorrect
PHP(function.php):
$Question=htmlentities($_POST['Question'],ENT_QUOTES,"UTF-8");
echo $Question[0]."<br>";
echo $Question[1]."<br>";
Now imagine that we enter "Hello" and "Bye" in the input So it should return "Hello" and "Bye" but it returns "q" and "u" instead.
The var_dump
out put is:
string(39) "question%5B%5D=Hello&question%5B%5D=Bye"
Edit 1
if I use .serialize()
I always get "q" and "u" but if I use .val()
I get the first and second letter of each word
Edit 2
I even tried the PHP code without htmlentities()
but the result is the same as before.