This is my code:
$.post('<?php echo site_url('channel_partners/get_cp_text'); ?>', {cp_lang: language},
function(data) {
alert('icon: ' + data.cp_icon);
}
);
The URL is CodeIgniter. Don’t be distracted by that. It returns the proper data, too. If I alert data I get the proper JSON-encoded array back. It looks like this.
{"cp_icon":"test1","authorized_cp":"test2"}
So I how do alert “test1” if not by data.cp_icon? If I use data.cp_icon, I get an undefined result.
Adding the data type will tell it to parse it as JSON and not as just a string (which is what is happening).