[英]how to use jquery Post in ASP.NET C#?
hi i had this function in my previous php site for posting data and getting response on page, but i can't figure it out in aspx page (not using mvc). 嗨,我在以前的php网站中具有此功能,用于发布数据并在页面上获取响应,但是我无法在aspx页面中找到它(不使用mvc)。 here is the code:
这是代码:
$.post('contact.aspx/submitdata', data, function () {
alert_msg.fadeOut();
form.find('.msg-thanks').fadeIn(function () {
textarea.val(textarea.attr('title'));
window.setTimeout(function () {
form.find('.msg-thanks').fadeOut();
}, 5000);
});
});
previously it was: 以前是:
$.post('mail/send.php', data, function () {
alert_msg.fadeOut();
form.find('.msg-thanks').fadeIn(function () {
textarea.val(textarea.attr('title'));
window.setTimeout(function () {
form.find('.msg-thanks').fadeOut();
}, 5000);
});
});
An the worst part is the method invoked doesnt come into debugging calls. 最糟糕的是,调用的方法不会进入调试调用。 here is the method:
这是方法:
[WebMethod]
public void SubmitData(string[] data) {
//do something;
}
The webmethod should be static. 该web方法应该是静态的。 You also need to set content type.
您还需要设置内容类型。
[WebMethod]
public static void SubmitData(string[] data) {
//do something;
}
$.ajax({
url: "contact.aspx/submitdata",
type: "POST",
contentType: "application/json; charset=utf-8",
data: data
})
.done(function (data) { //do something here on success})
.fail(function (jqXHR, status) { //error });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.