I keep on getting a JSON parser error (firebug console say 'There are no child objects') for the following data:
(String) var data from each iteration
var data='[';
data+= '{ "title": " Nac", "no1": "1212","no2": "12126"},';
data+= '{ "title": " Nac", "no1": "1212","no2": "12126"},';
data+= '{ "title": " Nac", "no1": "1212","no2": "12126"},';
data+= ']';
and javascript parsing json
var json = JSON.parse(data)
and jQuery AJAX request
$.ajax({
type: "POST",
data: json,
url : 'ticket.php',
dataType: 'json',
async: false,
contentType : 'application/json; charset=utf-8',
error: function(jqXHR, exception)
{
if (jqXHR.status === 0)
{
$('.item').html("err");
} else if (jqXHR.status == 404)
{
$('.item').html('err!');
} else if (jqXHR.status == 500)
{
alert("err!");
} else if (exception === 'parsererror')
{
$('.item').html('err parsererror');
} else if (exception === 'timeout')
{
$('.item').html('err!');
} else if (exception === 'abort')
{
$('.item').html('err!');
} else
{
$('.item').html('err!');
}
},
success : function(data)
{
alert("okey");
}
});
and ticket.php is completely empty because I don't no how receive json data from ajax in php
Any help would be highly appreciated. Thnks
JSON.parseon it and it worked okay