Here is my JSON function:
function createjson(){
var json='{"jsondata":[[';
$("#kup td").each(function(){
if($(this).html()!="")
{
json+= parseInt($(this).html())+",";
if($(this).index()%5==0 && $(this).index()!=0){
json=json.substring(0,json.length-1);
json+="],["
}
}
});
json=json.substring(0,json.length-3);
json+="]]}";
console.log(json); //-> works fine.
return json;
};
The AJAX part:
$("#button").click(function(){
$.ajax({
type:"POST",
url:"x.php",
data: createjson(),
contentType: "application/json",
dataType: "json",
success: function(result) {
alert("done"); //->works
}
});
});
The PHP part:
<?php
header('Content-type: application/json');
echo "<pre>";
echo $_POST['jsondata'];
echo "</pre>";
?>
So, the "alert" works but when check the response in console, it returns only "<pre></pre>
"
any solution?