我有一个简单的页面。加载时,它调用一个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 = [];
}
我的web服务:
[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,即使没有数据变量,它仍然会给出相同的错误。
我的最佳猜测是应该删除一些contentType/dataType,但我也尝试过。
你知道我为什么会犯这个错误吗?