i'm working on this now for about 2-3 hours and i cant find where i'm doing it wrong. this is my jQuery that is going to build an object:
var data = {cat:[],count:[],size:[],type:[],print:[]};
$("#Cat-list option").each(function()
{data.cat.push($(this).val());});
$("#Count-list option").each(function()
{data.count.push($(this).val());});
$("#Size-list option").each(function()
{data.size.push($(this).val());});
$("#Print-list option").each(function()
{data.print.push($(this).val());});
$("#Type-list option").each(function()
{data.type.push($(this).val());});
after this i will have an object named data. when i convert the obj to JSON by var jsonString=JSON.stringify(data);
it gives me something like this:
{
"cat":["Cart Visit","Bag","Envelope","Tracket","Brosur"],
"count":["1000","2000","4000","5000","?????"],
"size":["S","M","L","X"],
"type":["?? ??","??? ? ??","????"],
"print":["????","???????","????"]
}
then i use jQuery Ajax to send the jsonstring to my php file like this:
$.ajax({
type: "POST",
url: 'update_db.php',
data: jsonString,
contentType: "application/json; charset=utf-8",
success:
function(result) {
$( "#alert").html( result );
}
});
and finally i'm trying to recieve the data with php script. i dont know how to fetch the data for this i tried it with 'jsonstring' and 'data':
$json = json_decode( $_POST['jsonstring']);
$data = json_decode( $_POST['data']);
var_dump($json);
var_dump($data);
but both are "NULL". What am I doing wrong?