jquery - Ajax json Parser Error -


i keep on getting json parser error (firebug console 'there no child objects') following data:

(string) var data 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 empty because don't no how receive json data ajax in php

any highly appreciated. thnks

json.parse gives javascript object, if you're sending json in post send json not object. instead of building json string, build object , stringify it

var data= [{     "title": "  nac",     "no1": "1212",     "no2": "12126" }, {     "title": "new",     "no1": "12",     "no2": "121" }, {     "title": "san",     "no1": "1227",     "no2": "1" }]; var json = json.stringify(data);         $.ajax({         type: "post",         data: json,         url : 'ticket.php',         datatype: 'json',         async: false,         contenttype : 'application/json; charset=utf-8',         ... 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -