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.

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.