I have a "hello world" wcf service:
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>
And I have a very simple HTML page:
$.ajax({
type: "GET",
url: "http://localhost:49311/Service1.svc/GetData/",
dataType: "xml",
success: function () {
alert("test ok");
},
error: function (e) {
alert("error: " +e.responseText);
}
});
I'm getting the following error: XMLHttpRequest cannot load localhost:49311/Service1.svc/GetData. Origin null is not allowed by Access-Control-Allow-Origin
Is there a easier way fixing this cross site/port issue?
Thanks!
您的服务器端期望从请求中发送一些来源,并且当前它为空,请使用charles或fiddler来检查您的请求
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.