5

I am trying to get the JSON data from a URL that outputs the following JSON data:

[
 {
    "belief_desc":"Jesus Died For Your Sins",
    "0":"Jesus Died For Your Sins"
 },
 {
    "belief_desc":"People Are Sinful",
    "0":"People Are Sinful"
 },
 {
    "belief_desc":"God Loves You",
    "0":"God Loves You"
 },
 {
    "belief_desc":"We Must Receive Christ",
    "0":"We Must Receive Christ"
 }
]

(Note: it is only formatted in this question for easier reading.)

Now I am trying to parse through it using this simple jQuery script:

<script>
    var url = "http://mySite.com/data.json";
    $.getJSON(url, function(data){
        alert(data);
        });
</script>

I am getting no data from the URL as the alert will not show. Any ideas on why this is not working?

Mike Richards
  • 939
  • 3
  • 14
  • 23

1 Answers1

4

Cross domain you can't do simple JSON.

Basic how-to for cross domain jsonp

Read up on cross domain requests.

Community
  • 1
  • 1
Leeish
  • 5,203
  • 2
  • 17
  • 45
  • I am still not having any luck. I'm using the example from http://stackoverflow.com/questions/2681466/jsonp-with-jquery and simply replacing the URL. Could it have to do with how I encode the JSON url? I am using json_encode with PHP on an array from a MySQL database. – Mike Richards Feb 06 '13 at 17:39
  • It's most likely something server side, (the side which is generating the JSON data). I am not familiar with cross-domain JSON, I just know there are some extra hoops to jump through to get it to work. – Leeish Feb 06 '13 at 18:15