php - ajax / json output must be an other format -


hi jquery map values on ajax. format map must var new_sample_data = {"af":"16.63","al":"11.58","dz":"158.97",...};.

i have tested var new_sample_data = {"af":16.63,...}; , works good. if take on jason. doesn't work. must change?

the php testcode:

$sample_data[] = array("de","$de");  echo json_encode($sample_data); 

the javascript code:

        $.ajax({          type: "post",                                             url: '../mail/assets/includes/geodata1.php',         data: {datum1: date.today().add({days: -29}).tostring('yyyy-mm-dd'), datum2: date.today().tostring('yyyy-mm-dd')},         datatype: 'json',         success: function(data)         {         var new_sample_data = data; 

in firebug see response [["de","4"]]. how can change format map need?

you need create associative array in php:

$sample_data = array("de"=>"$de");

then encoding should result in proper json string can parsed javascript object.

to see proper content of new_sample_data in javascript, use console.dir(new_sample_data);, list object's attributes.

you can access value of new attribute way in javascript:

console.log(new_sample_data.de);


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -