我写了第一个WCF服务
这是服务方法
public Employee GetEmployee()
{
Employee objEmp = new Employee();
objEmp.EmpName = "Jay";
objEmp.EmpAddress = "Delhi";
return objEmp;
}
这是合同
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
Employee GetEmployee();
这是jQuery AJAX调用
$(function () {
$.ajax({
type: 'GET', //GET or POST or PUT or DELETE verb
url: 'Service1.svc/GetEmployee', // Location of the service
contentType: "application/json; charset=utf-8", // content type sent to server
dataType: 'json', //Expected data format from server
success: function (msg) {//On Successfull service call
alert('success');
console.log(msg);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
}
});
});
它运行良好但很好,但我不会将数据作为JSON而是作为对象
答案 0 :(得分:0)
将dataType更改为dataType: 'text',
可以解决问题......:)