访问控制允许来源.从javascript调用WCF服务时出错 [英] Access-Control-Allow-Origin. error when I call WCF service from javascript
本文介绍了访问控制允许来源.从javascript调用WCF服务时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过javascript调用WCF服务.
在控制台中运行应用程序时,出现以下错误:
I''m making a call to WCF services from javascript.
When I run the application in Console I''m getting the following error:
**Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
http://localhost:8732/IServices/RoleService/json/Role/{engineer}
XMLHttpRequest cannot load
http:/http://localhost:8732/IServices/RoleService/json/Role/{engineer}Origin
http://localhost:3952 is not allowed by Access-Control-Allow-Origin.**
我的代码就像..
My code is like..
<script src="~/Scripts/jquery-1.5.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
debugger
function GetRoles() {
$("#btnWCFREST").click(function () {
$.ajax({
async: true,
url:"http://localhost:8732/IServices/RoleService/json/Role/doctor",
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (msg) {
alert(msg);
},
error: function (msg) {
alert("Failed");
}
});
});
}
</script>
如何解决此问题?
我正在本地主机中运行应用程序
谢谢,
How can I fix this issue?
I am running the application in localhost
Thanks,,
推荐答案
(" ).click(函数(){
("#btnWCFREST").click(function () {
.ajax({ 异步: true , url:" , 类型:" , dataType:" , contentType:" , 成功:功能(msg){ 警报(msg); }, 错误:功能(msg){ alert(" ); } }); }); } </script>
.ajax({ async: true, url:"http://localhost:8732/IServices/RoleService/json/Role/doctor", type: "GET", dataType: "json", contentType: "application/json; charset=utf-8", success: function (msg) { alert(msg); }, error: function (msg) { alert("Failed"); } }); }); } </script>
如何解决此问题?
我正在本地主机中运行应用程序
谢谢
How can I fix this issue?
I am running the application in localhost
Thanks,,
这篇关于访问控制允许来源.从javascript调用WCF服务时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文