function SendEditCommand()
{
jQuery.ajax({
url: 'http://localhost:15478/Service.svc/GetTest',
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert('success');
},
error: function(request, status, error) {
alert(error);
}
});
}
jQuery(document).ready(function () {
SendEditCommand();
});
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="Entities" connectionString="metadata=res://*/Data.TechieCMS.csdl|res://*/Data.TechieCMS.ssdl|res://*/Data.TechieCMS.msl;provider=System.Data.SqlClient;provider connection string="Data Source=localhost\mssql2008;Initial Catalog=TechieCMS;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.serviceModel>
<services>
<service name="DefaultService" behaviorConfiguration="DefaultServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="Techie.CMS.Business.ContentProvider" behaviorConfiguration="DefaultEndpointBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="DefaultEndpointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
</configuration>
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ContentProvider
{
[OperationContract]
[WebGet()]
public string GetTest()
{
return "Test";
}
}
答案 0 :(得分:1)
我猜它不喜欢URL中的端口。其他一切都是正确的。你在用IE吗?它适用于其他浏览器吗?其他有相同问题的人一直使用IE浏览器,它适用于Firefox。
也许尝试添加数据变量并将其更改为POST?有人说这解决了。
答案 1 :(得分:0)
谢谢大家的答案,他们肯定是相关的,也是拼图的一部分。关键问题是&lt; service name =“DefaultService”......我认为这应该是我选择的名称。发现它必须是实现合同的类的完全限定名称。