如何使用wcf服务解决跨域问题 [英] how to resolve cross-domain issues using wcf services
本文介绍了如何使用wcf服务解决跨域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
how to resolve cross-domain issues using wcf services
以下是我的代码:
below is my code :
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: 'http://localhost:49878/Employee.svc/GetEmployeeList',
dataType: "json",
success: function (data) {
//alert(data.d);
$($.parseJSON(data.d)).each(function (index, value) {
$("#TableID").append("<tr><td>" + value.EmpId + "</td><td>" + value.EmpName + "</td><td>" + value.Desgination + "</td></tr>");
});
},
error: function (result) {
// alert(result);
}
});
服务代码:
Services Code:
private static void ResponseHeaders()
{
WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Origin", "*"); WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Methods", "POST"); WebOperationContext.Current.OutgoingResponse.Headers.Add(
"Access-Control-Allow-Headers", "Content-Type, Accept");
}
public List<Employe> GetEmployeeList()
{
var listEmployee = new TestEntities().Employes.ToList();
ResponseHeaders();
return listEmployee;
}
推荐答案
.ajax({
type: POST,
contentType: application / json; charset = utf-8,
url:' http: //localhost:49878/Employee.svc/GetEmployeeList',
dataType: json,
成功:功能(数据){
// alert(data.d);
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: 'http://localhost:49878/Employee.svc/GetEmployeeList', dataType: "json", success: function (data) { //alert(data.d);
(
.parseJSON (data.d))。each( function (index,value){
.parseJSON(data.d)).each(function (index, value) {
这篇关于如何使用wcf服务解决跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文