I would like to pass a string that has been serialized by JSON using $.ajax to an external php file to be assigned to a regular array.
Here is what I got so far which isn't showing 0th index of taskContent array.
JQuery code:
$(".json").click(function() {
var allTaskArr = [];
$('#appendTask .taskbox').each(function(index,domEle){
//domEle == this
allTaskArr[index] = $(domEle).val();
});
var allTaskStr = '{"taskContent":'+JSON.stringify(allTaskArr)+'}';
$.ajax({
url:'testjson.php',
type:"POST",
datatype:'json',
data:allTaskStr
});
});
PHP file:
$jsonContent = $_POST['taskContent'];
$taskContent = json_decode($jsonContent,true);
echo $taskContent[0];
alert(allTaskStr);in the JQuery file, I'd get {"taskContent":["text-1","text-2"]}, then I'd assign text-1 and text-2 to index-0 and 1 of the taskContent array in the PHP file.<?phpprint_r($_POST)look like?