我有一个简单的页面。加载时,它调用 Web 服务,然后我收到以下错误:
an attempt was made to call the method using a GET request, which is not allowed
我的 JS 代码:
function getTutors() {
var url = '<%= ResolveUrl("~/services/tutorservice.asmx/gettutors") %>';
$.ajax({
type: "GET",
data: "{'data':'" + 'test-data' + "'}",
url: url,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (d) {
alert('succes');
return d;
},
error: function () {
alert('fejl');
}
});
}
$(document).ready(function () {
var tutors = getTutors();
var locations = [];
}
我的网络服务:
[ScriptService]
public class tutorservice : System.Web.Services.WebService {
public tutorservice () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public List<Tutor> gettutors(string data)
{
var tutorManager = new TutorManager();
return tutorManager.GetTutorApplicants();
}
}
我试图删除 contentTypes,即使没有 data 变量,它仍然会给出相同的错误。
我最好的猜测是应该删除一些 contentType / dataType,但我也尝试过。
关于我为什么会收到此错误的任何想法?