<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>webservices example </title>
<link rel="stylesheet" href="jquery.mobile-1.1.0.css" />
<link rel="stylesheet" href="my.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type:"GET",
url:"http://shoperola.com/Restaurant/foodysrest/sample",
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: "json",
xhrFields: {
withCredentials: true
},
beforeSend: function (request) {
request.setRequestHeader("Access-Control-Allow-Origin: ", "*")
},
success: function(data) {
alert(data);
},
error: function(data) {
alert("Error in Processing-----" + data.status);
}
});
});
</script>
</head>
</html>
“XMLHttpRequest 无法加载 http://shoperola.com/Restaurant/foodysrest/sample ?{}。请求的资源上不存在“Access-Control-Allow-Origin” header 。因此不允许访问源“http://:8088””。
最佳答案
您正在尝试对另一个域执行XMLHttpRequest(AJAX)
。
出于安全原因,此操作受到限制。
更多详情请参见: http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
关于jquery - 请求的资源上不存在 'Access-Control-Allow-Origin' header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20973622/