0

Having some trouble getting a JSON feed to load from my site. I'm starting to think something is wrong with the feed itself, since plugging the address into a variety of different blocks of example code doesn't seem to work.

I've tried the examples below, and continually meet with "Origin null is not allowed by Access-Control-Allow-Origin" when trying to deep drill the error through Chrome's Javascript Console. Any ideas?

Try #1:

    <script type="text/javascript">
        $().ready(function(){ 
            var url = 'http://www.solidverbal.com/category/clicks?feed=json';
            $.get(url, function(data) {
                // can use 'data' in here...
            });
        });

    </script>

Try #2:

<script type="text/javascript">
        $.ajax({
            type: "POST",
            url: "http://www.solidverbal.com/category/clicks?feed=json",
            data: '{}', // your parameter goes here
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            processdata: true,
            success: function (msg) {
                loadDetails(msg.d);  // msg.d contains the JSON data being returned
            },
            error: function (msg, error, obj) {
                alert(msg.responseText);
            }
        });


        function loadDetails(results) {
            // depending on the data in the JSON object, you can access them using
            // the syntax results.<propertyname>  etc…
        }

    </script>
2
  • 2
    Is solidverbal.com your domain? Commented Feb 17, 2011 at 23:00
  • Obvious potential error: origin null means you're running this on your local machine's file system. Chrome won't let you do AJAX calls when doing this. Commented Feb 17, 2011 at 23:02

1 Answer 1

1

Due to same origin policy restrictions you are not allowed to perform cross domain AJAX calls. So unless the page you are running this script from is hosted on http://www.solidverbal.com this won't work. As a possible workaround you could use JSONP if the remote domain supports it or supply a server side script on your domain that will serve as bridge between your domain and the remote domain and then perform the AJAX call to this script.

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

Comments

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.