1
您好我做了一個WCF服務從Jquery訪問它在IE 8,IE中工作,但它不工作在Firefox。Jquery Ajax調用WCF不工作在Firefox
這是我的服務類
namespace JSONSample
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
Employee[] getData();
}
[DataContract]
public class Employee
{
[DataMember]
public string id { get; set; }
[DataMember]
public string name { get; set; }
}
}
而實施Webconfig
namespace JSONSample
{
public class Service1 : IService1
{
#region IService1 Members
public Employee[] getData()
{
return new Employee[] { new Employee() { id = "1", name = "John" }, new Employee() { id = "2", name = "Bourne" }, new Employee() { id = "3", name = "Harry" } };
}
#endregion
}
}
端點我創建了終點
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="JSONSample.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="JSONSample.Service1Behavior" name="JSONSample.Service1">
<endpoint address="" binding="webHttpBinding" contract="JSONSample.IService1" behaviorConfiguration="web"/>
</service>
</services>
</system.serviceModel>
從通話HTML我使用的是GET和任何數據未發送到服務器
jQuery.support.cors = true;
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://localhost:51220/Service1.svc/getdata",
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: false,
success: function(msg) {
alert(msg);
},
error: function ServiceFailed(result) {
alert('Service call failed: ' + result.status + '' + result.statusText);
}
});
});
這是爲什麼僅工作在IE和Firefox的不
您應該考慮使用帶有JsonResult ...或MVC4 Web API的ASP.NET MVC3 Action。 –