我有以下JavaScript代码。它只是类,它应该从REST WCF客户端接收一些数据。代码引发异常'[specific_method]未定义'
class EmployeesWcfClient {
constructor(url) {
if (url == null) {
url = "http://localhost:35798/MyCompanyService.svc/";
}
this.url = url;
}
doGetRequest(relUrl) {
return $.ajax({
type: 'GET',
contentType: 'json',
dataType: 'json',
url: this.url + relUrl,
async: false
});
}
doPostRequest(relUrl, data) {
return $.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
dataType: "json",
url: this.url + relUrl,
async: false
});
}
getEmployees() {
return doGetRequest('Employees');
}
}
我不知道为什么会引发异常:'doGetRequest未定义'。有人可以帮忙吗?
你不能在JS/JQ中创建类。如果您尝试创建类'类EmployeesWcfClient',那么编译器将创建一个具有相同名称的函数 –