I have a php web service returning json data. My problem is that when i call the json data from url returns nothing but when a call a local file with exactly the same data (copy from the url) works fine.

The json data i receive are for example

    {"ResponseData":[{"Code":"91010001","Description":"ISADORA ","retailprice":"52.0000000000"},{"Code":"91010002","Description":"ISADORA ","retailprice":"52.0000000000"}]}

The script i use to get the json data is



                        var output = '';

          $.each(data.ResponseData, function(i,data){
             output += '<li><a href="#">' + data.Code + '</a></li>';
             if ( i == 50 ) return false;



Finally, I used an ajax script just to display the json data but returns me error [object Object].

     var obj 
    url: 'url",
    type: "GET",
    dataType: 'json',
    success: function( data ) {
      alert( "SUCCESS:  " + data );
    error: function( data ) {
    var obj = $.parseJSON(JSON.stringify(data));
      alert( "ERROR:  " + data );

Do you have any idea how to fix this?

Thanks in advance


Hope this helps: In application craft i used first a function obj2json to convert data to json and then json2obj to populate data.

5 Years
Discussion Span
Last Post by ko ko

What's your json file extension ? Have you also put header in your json output file which is 'url' in your script ? Try to set header in your 'url' file with 'Content-type: application/json' or 'Content-type: application/javascript' if you're using javascript file for json data. Example

$jsonfile = file_get_contents('your_json_file.json'); //in this case .json extension is used
$json = json_encode($jsonfile);
header('Content-type: application/json');
echo $json;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.