我有一个"你好世界"wcf服务:
public string GetData()
{
return "Hello world";
}
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
我有一个非常简单的HTML页面:
$.ajax({
type: "GET",
url: "http://localhost:49311/Service1.svc/GetData/",
dataType: "xml",
success: function () {
alert("test ok");
},
error: function (e) {
alert("error: " +e.responseText);
}
});
我收到以下错误:XMLHttpRequest无法加载localhost:49311/Service1.svc/GetData。Access Control Allow Origin 不允许Origin null
有没有更简单的方法来解决这个跨站点/端口的问题?
谢谢!
您的服务器端希望从请求中发送一些来源,但当前它为null,请使用charles或fiddler检查您的请求