我正在umbraco网站上创建一个带有ajax帖子的电子邮件联系表单,我正在通过它,只是测试ajax部分,我得到一个" Web服务方法名称无效"运行时出错。
我在app_code中有booking.cs,然后在webservice文件夹中有booking.asmx,
[WebService(Namespace = "http://localhost/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class Booking : System.Web.Services.WebService
{
public string Email { get; set; }
[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public string SaveIt(string Email)
{
try
{
return "success";
}
catch (Exception er)
{
return "error";
}
}
}
的javascript:
$("#email_popup_submit").click(function (e) {
$.ajax({
url: '/webservice/Booking.asmx/SaveIt',
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: { 'Email': 'testemail' },
beforeSend: function () {
},
success: function (data) {
//console.log(data.d);
if (data.d == "success") {
e.preventDefault();
// console.log('SUCCESS!');
} else {
}
},
error: function (jqXhr, textStatus, errorThrown) {
console.log("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')");
}
});
})
答案 0 :(得分:0)
从service code
enabled
取消注释以下来自javascript/ajax
的来电
[System.Web.Script.Services.ScriptService]
答案 1 :(得分:0)
您可以尝试将数据参数更改为:
data: '{ "Email":"testemail"}'