ASP.NET Webform 与JQuery Ajax
2017-11-15 20:02
239 查看
在webform 中使用AJAX 能把人逼疯:)
以下介绍的是在aspx页面的code-behind 中添加静态方法的方法:
(敲黑板)以下是注意点:
方法一定是静态的。
[webmethod] 一定要加。
方法中的参数一定要和Ajax传过来的对应。
AJAX type 要用post
Here we go ! Index.apsx.cs:
index.aspx:
var userData = "{username:'test1',pwd:'password'}";//一定要写在外面
$.ajax({
type: 'post',
url: 'NormalPage.aspx/Login',
dataType: 'json',
contentType: 'application/json',
data: userData,
success: function (result) {
alert(result.d);
},
error: function () {
alert('error');
}
});
以下介绍的是在aspx页面的code-behind 中添加静态方法的方法:
(敲黑板)以下是注意点:
方法一定是静态的。
[webmethod] 一定要加。
方法中的参数一定要和Ajax传过来的对应。
AJAX type 要用post
Here we go ! Index.apsx.cs:
[WebMethod] public static string Login(string username,string pwd) { return username + pwd; }
index.aspx:
var userData = "{username:'test1',pwd:'password'}";//一定要写在外面
$.ajax({
type: 'post',
url: 'NormalPage.aspx/Login',
dataType: 'json',
contentType: 'application/json',
data: userData,
success: function (result) {
alert(result.d);
},
error: function () {
alert('error');
}
});
相关文章推荐
- ASP.NET webform基于Jquery,AJAX的三级联动
- asp.net利用Ajax和Jquery在前台向后台传参数并返回值
- asp.net+ajax + -Jquery 无刷新评论(留言)系统 v1.0 (漂亮验证码 ,载入等待状态)
- JQuery Form Ajax提交Asp.Net表单时的验证视图状态 MAC 失败
- 在Asp.net中使用jquery实现Ajax
- asp.net mvc jquery+js+ajax 实现联动
- jQuery+ASP.NET的AJAX文件上传
- Many ways to communicate with your database using jQuery AJAX and ASP.NET
- jquery+ajax(asp.net)
- JQuery Form Ajax提交Asp.Net表单时的验证视图状态 MAC 失败
- Asp.net MVC中 model 验证方式 ajax +jquery
- Asp.Net+Jquery.Ajax详解1-开篇
- asp.net AJAX 验证用户名是否存在 -Jquery
- Asp.Net+Jquery.Ajax详解2-$.Load
- Asp.Net+Jquery.Ajax详解4-$.getJSON
- Asp.net Ajax,Jquery,ExtJs 三种Ajax技术框架比较
- 在Asp.net中使用jquery实现Ajax
- Ajax 实现在WebForm中拖动控件并即时在服务端保存状态数据 (Asp.net 2.0)(示例代码下载)
- asp.net中使用jquery的ajax来post数据的树控件
- 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法