[英]Jquery to parse Json “Origin null is not allowed by Access-Control-Allow-Origin”
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 . XMLHttpRequest无法加载http://api.angel.co/1/tags/1654/startups?callback=aaa 。 Origin null is not allowed by Access-Control-Allow-Origin.
Access-Control-Allow-Origin不允许使用Origin null。
Try use jquery ajax
: 尝试使用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 );
}
});
Origin null is not allowed by Access-Control-Allow-Origin Access-Control-Allow-Origin不允许使用原点null
You can't hit another domain ( different from what you are on ) using XMLHttpRequest unless you use JSONP 除非使用JSONP,否则您无法使用XMLHttpRequest 来访问另一个域( 不同于您所在的域)
read more about Same_origin_policy 阅读有关Same_origin_policy的更多信息
You must be hosted on some server to run AJAX otherwise it will always say 您必须托管在某些服务器上才能运行AJAX,否则它将始终显示
Origin null is not allowed ...
Try WAMP/LAMP or use Apache tomcat to run your HTML code on localhost. 尝试使用WAMP / LAMP或使用Apache tomcat在本地主机上运行HTML代码。 It will make your domain localhost instead of null and will fix it.
它将使您的域localhost而不是null并将对其进行修复。
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. PS:跨域问题可能仍然存在,具体取决于您选择的服务器是否允许您从中获取数据或将数据发布到该服务器。
The following should work: 以下应该工作:
$.getJSON("http://api.angel.co/1/tags/1654/startups?callback=?", function(data) {
$(body).append(data);
});
jQuery will replace the ? jQuery将取代吗? with a generated function name that calls the inline function.
使用生成的函数名称调用内联函数。
Include the attribute, "dataType" with the value "JSONP" in yours ajax call. 在您的ajax调用中将属性“ dataType”与值“ JSONP”一起包含。 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);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.