1

Where am i going wrong with this

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>title</title>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$.get("http://api.angel.co/1/tags/1654/startups?callback=aaa",
   function(data) {
     $('body').append( "Name: " + data );
   }, "json");

</script>

    </head>

<body>

</body>
</html>

XMLHttpRequest cannot load http://api.angel.co/1/tags/1654/startups?callback=aaa. Origin null is not allowed by Access-Control-Allow-Origin.

Dasa
  • 297
  • 1
  • 7
  • 23
  • 1
    Have you tried using the developer tools in Chrome or Firefox to examine the details of your request and the response? – Dogoferis Apr 21 '13 at 11:09
  • XMLHttpRequest cannot load http://api.angel.co/1/tags/1654/startups?callback=aaa. Origin null is not allowed by Access-Control-Allow-Origin. is all i get – Dasa Apr 21 '13 at 11:18
  • possible duplicate of http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin?rq=1 – Amelia Apr 21 '13 at 11:26

5 Answers5

9

Try use jquery ajax:

$.ajax({
    url:"http://api.angel.co/1/tags/1654/startups?callback=aaa",
    type:'GET',
    dataType:'JSONP',
    success: function(data){
        $('body').append( "Name: " + data );
    }
});
Mohamed AbdElRazek
  • 1,654
  • 14
  • 17
2

Origin null is not allowed by Access-Control-Allow-Origin

You can't hit another domain (different from what you are on) using XMLHttpRequest unless you use JSONP

read more about Same_origin_policy

Community
  • 1
  • 1
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
2

You must be hosted on some server to run AJAX otherwise it will always say

Origin null is not allowed ...

Try WAMP/LAMP or use Apache tomcat to run your HTML code on localhost. It will make your domain localhost instead of null and will fix it.

PS: Cross domain problem may still persist depending upon the server you are hitting whether it allows you to get/post data from/to it.

Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
0

The following should work:

$.getJSON("http://api.angel.co/1/tags/1654/startups?callback=?", function(data) {
    $(body).append(data);
});

jQuery will replace the ? with a generated function name that calls the inline function.

0

Include the attribute, "dataType" with the value "JSONP" in yours ajax call. Refer the below example code:

$.ajax({
    url: "http://api.angel.co/1/tags/1654/startups?callback=aaa",
    dataType:'JSONP',
    success: function(data) {
        $('body').append( "Name: " + data.name);
    }
});
Srinivasan.S
  • 3,065
  • 1
  • 24
  • 15