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?

6
  • Can you use Firebug and see what is coming back in the console? Just to be super sure? Is your page located on bsucru.comoj.com? If not, you can't do JSON due to security reasons. Commented Feb 6, 2013 at 16:20
  • Is your page on bsucru.comoj.com somewhere or another domain? Commented Feb 6, 2013 at 16:22
  • The page I am running the script is not on that domain. I am just using a local page to try and get that data. Commented Feb 6, 2013 at 16:25
  • which browser are you using? Commented Feb 6, 2013 at 16:25
  • you are not allowed to make cross domain ajax requests. if you are using chrome, start it with --disable-web-security option. This will let you make cross domain requests. Commented Feb 6, 2013 at 16:27

1 Answer 1

4

Cross domain you can't do simple JSON.

Basic how-to for cross domain jsonp

Read up on cross domain requests.

Sign up to request clarification or add additional context in comments.

2 Comments

I am still not having any luck. I'm using the example from 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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.