JSON.parse() is not converting my PHP string to a JavaScript object -


i have used json_encode() echo associative array php javascript through $.post method:

$.post("php/myfile.php", {}, function(data){     exercises = data;     //exercises = json.parse(data);   // console -> uncaught referenceerror: json not defined     alert(typeof exercises);          // alerts -> string     alert(exercises);                 // alerts -> {"1":"bench press","2":"squat","3":"deadlift"}     alert(json.stringify(exercises)); // console -> uncaught referenceerror: json not defined }); 

for reason can't convert string javascript associative array using json.parse().

what's issue?

you can pass json datatype ajax call jquery pass converted value

$.post("php/myfile.php", {}, function (exercises) {     alert(typeof exercises); // alerts -> string     alert(exercises); }, 'json'); 

in code problem case of json, should json.parse() not json.parse()


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -