我正在尝试从Web Service获得一些返回值,我正在使用ajax jQuery。
我收到了这些错误:
XMLHttpRequest无法加载' http ....'。 No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' http://localhost:8181'因此不允许访问
XHR加载失败:GET" http ..."。
<script language="text/javascript">
getUserValue();
function getUserValue() {
var number = "0000317930";
var fullName = "NURULLAH ALTINTAŞ";
var dataString = "{ 'number' : '" + number + "', 'fullName' : '" + fullName + "'}";
$.ajax({
type: "GET",
url: "http://...",
data: {
number: number,
fullName: fullName
},
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
dataType: "xml",
success: OnSuccessGetConnectionArticles,
failure: OnFailureGetConnectionArticles,
error: OnErrorGetConnectionArticles
});
}
function OnSuccessGetConnectionArticles(response) {
debugger;
$.each(response.RestResponse.result, function(index, value) {
$("#list").append('<li><span class="tab">' + value.name + '</span></li>');
});
}
function OnErrorGetConnectionArticles(response) {
debugger;
alert(response.d);
}
function OnFailureGetConnectionArticles(response) {
debugger;
alert(response.d);
}
</script>
答案 0 :(得分:1)
如果您在服务器端使用 PHP ,则应在请求的页面中使用以下代码::
$origin = 'http://localhost:8181';
header("Access-Control-Allow-Origin: " . $origin);
如果您正在使用其他一些语言,那么您应该发现类似的内容。
答案 1 :(得分:0)
我认为您应该将这些行添加到您的web.config文件中以获取Allow-Origin错误。
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>