0

My server side code is:

$bus = array(
       'meaning' => $name
       );

$jsonstring = json_encode($bus);
echo $_GET['callback'].'(' . $jsonstring. ')';

the value displayed on the screen is correct - ?word=heart({"meaning":"heart"}) but when I am reading it with following code its printing the value of meaning as 11200665987893779229_1460521505942

$(document).ready(function(){
    $.getJSON('http://mydomain?callback=?','word=heart',function(res){
     document.getElementById('print').innerText=''+res.meaning;
    });
});

but when I do this:

$bus = array(
       'meaning' => 'heart'
       );

it's printing the correct value i.e heart

I am not getting why this is happening and how to get the correct value (I am accessing data from my different domain).

Rasclatt
  • 12,498
  • 3
  • 25
  • 33

1 Answers1

0

JSON.parse() converts any JSON String passed into the function, to a JSON Object.

$(document).ready(function(){
$.getJSON('http://mydomain?callback=?','word=heart',function(res){
obj = JSON.parse(res);
 document.getElementById('print').innerText=''+obj.meaning;
});

});

a similar post is here

Community
  • 1
  • 1
saeedeh
  • 343
  • 2
  • 7