I am trying to send or retrieve, not sure where the fault is, in a specific way...
Here is how it should look when using JSON.stringify(test):
{"1":"<div class=\"test\">test1</div>","2":"<div class=\"test\">test2</div>","1":"<div class=\"test\">test1</div>"}
But my ajax/json return looks like this:
["'1':'<div class='test'>test1</div>'","'2':'<div class='test'>test2</div>'","'3':'<div class='test'>test3</div>'"]
I need curly brackets at the beginning and " not to be there.
Here is how I send and get data.
test.php
$test = array();
$test[] = array('id' => '1', 'name' => 'test1');
$test[] = array('id' => '2', 'name' => 'test2');
$test[] = array('id' => '3', 'name' => 'test3');
echo json_encode($test);
And the javascript which retrieves it:
var mytest = [];
$.getJSON('test.php', function(data){
$.each(data, function (i, val) {
mytest.push("'"+val.id+"':'<div class='test'>"+val.name+"</div>'");
});
alert(JSON.stringify(mytest));
});
Really hoping for help... I am stuck. Thanks in advance :-)