jQuery Ajax 在 url 路由后不调用 webmethod
我的 jquery ajax 函数没有调用 webmethod。 jquery 函数返回 Web 服务页面的 html。 函数不明白“ebulten_add”是一个webmethod!
“url:ajaxPage.aspx/e_bulten”
写或不写是相同的..都返回ajaxPage.aspx html。
$.ajax({
type: "POST",
url: 'ajaxPage.aspx/ebulten_Add',
data: "{ebEmail:'" + Ebemail + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$("#span_result").hide();
$("#span_spinner").hide();
$("#span_result").html(result.d).fadeIn();
},
error: function (msg) {
$("#span_result").hide();
$("#span_spinner").hide();
$("#span_result").html("Lütfen tekrar deneyin.").fadeIn();
}
});`
ajaxPage.aspx 中的 Web 方法
[System.Web.Services.WebMethod]
public static string ebulten_Add(string ebEmail)
{
if (ebEmail == "Email")
{
return "*Bilgilerinizi Girmediniz";
}
else
{
List<ListItem> ebList = new List<ListItem>();
ebList.Add(new ListItem("@Eb_email", ebEmail));
BL.Atom.GetByVoid("spEbulten_Add", ebList);
return "*E-Bülten kaydınız başarıyla tamamlanmıştır";
}
}
my jquery ajax function is not calling webmethod. jquery function return webservice page's html.
function is not understand "ebulten_add" is a webmethod!
"url:ajaxPage.aspx/e_bulten"
to write webmethod name or not write is same.. both of return ajaxPage.aspx html.
$.ajax({
type: "POST",
url: 'ajaxPage.aspx/ebulten_Add',
data: "{ebEmail:'" + Ebemail + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$("#span_result").hide();
$("#span_spinner").hide();
$("#span_result").html(result.d).fadeIn();
},
error: function (msg) {
$("#span_result").hide();
$("#span_spinner").hide();
$("#span_result").html("Lütfen tekrar deneyin.").fadeIn();
}
});`
web method in ajaxPage.aspx
[System.Web.Services.WebMethod]
public static string ebulten_Add(string ebEmail)
{
if (ebEmail == "Email")
{
return "*Bilgilerinizi Girmediniz";
}
else
{
List<ListItem> ebList = new List<ListItem>();
ebList.Add(new ListItem("@Eb_email", ebEmail));
BL.Atom.GetByVoid("spEbulten_Add", ebList);
return "*E-Bülten kaydınız başarıyla tamamlanmıştır";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如我所看到的,您返回的是字符串而不是 json,
因此只需更新您的 dataType: 'text' 就可以了
As I can see, you are returning string not json
so just update your dataType: 'text' and it should be ok
同意@SenadM。更改
dataType:text
或从 webmethod 返回 JSON:另外,请确保在 web.config 中启用了 POST:
Agree with @SenadM. Either change the
dataType:text
or return JSON from your webmethod:Also, make sure POST is enabled in your web.config:
只需将
var settings = newFriendlyUrlSettings {AutoRedirectMode = RedirectMode.Permanent};
更改为varsettings = newFriendlyUrlSettings {AutoRedirectMode = RedirectMode.Off};
这应该可以解决问题。Just Change
var settings = new FriendlyUrlSettings {AutoRedirectMode = RedirectMode.Permanent};
tovar settings = new FriendlyUrlSettings {AutoRedirectMode = RedirectMode.Off};
This should solve the problem.