0

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

<script>$.getJSON("url",

        function(data){

                        var output = '';

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

          });
             $('#listview1').append(output).listview('refresh');
        });

     </script>

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

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

Do you have any idea how to fix this?

Thanks in advance

EDIT:

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

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by ko ko
0

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

<?php
$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.