【Web】【Ajax】Ajax调用Aspx后台方法
来源:互联网 发布:淘宝无线展现词没有了 编辑:程序博客网 时间:2024/05/29 19:48
Ajax调用的前提(以aspx文件为例:)
1、首先需要在aspx文件后台中引用using System.Web.Services;
2、需要调用的方法必须是公共的(public)、静态的(static);如果不是会提示“500 Internal Server Error 问题”,代表找不到method。
3、方法定义需要加入[WebMethod]的声明
4、一般建议由返回类型,最起码可能知道调用成功不成功。
下面是简单的调用示例:
无参调用
后台方法
[WebMethod] public static string setAlert() { return "1"; }
Ajax调用
$.ajax({ url: "test.aspx/setAlert", //调用路径及方法 type: "post",//提交方式 dataType: 'json',//数据传递类型 contentType: "application/json;charset=utf-8",//设置内容类型,即在页面中传递的方式及编码方式 success: function (data) {//如果成功,接收返回结果 alert(data.d);//输出返回结果,需要注意的是,更具不同数据类型,会存在不同的数据处理方式,这里使用的是单个字符串数据,可以直接使用,如果是多个,需要分别接受返回的数据 }, error: function (data) { alert(false);//如果调用错误,则返回false } });
有参调用
后台方法
[WebMethod] public static string setAlert(string s) { return s+"123"; }
Ajax调用
$.ajax({ url: "test.aspx/setAlert", //调用路径及方法 type: "post",//提交方式 data:"{'s':'Dongle'}",//传递参数 dataType: 'json',//数据传递类型 contentType: "application/json;charset=utf-8",//设置内容类型,即在页面中传递的方式及编码方式 success: function (data) {//如果成功,接收返回结果 alert(data.d);//输出返回结果,需要注意的是,更具不同数据类型,会存在不同的数据处理方式,这里使用的是单个字符串数据,可以直接使用,如果是多个,需要分别接受返回的数据 }, error: function (data) { alert(false);//如果调用错误,则返回false } });
0 0
- 【Web】【Ajax】Ajax调用Aspx后台方法
- Ajax三级联动调用aspx后台方法
- JQuery .ajax方法直接调用aspx后台代码
- Ajax调用后台方法
- Ajax 调用后台方法
- ajax调用后台方法
- ajax调用后台方法
- JQuery AJAX请求aspx后台方法
- Jquery Ajax调用aspx页面方法
- 运用ajax和jquey直接调用Aspx.cs后台的方法
- ajax后台调用前台方法
- jquery ajax调用后台方法
- jQuery Ajax 调用后台方法
- .net ajax调用后台方法
- JQ AJAX 调用后台方法--
- Ajax调用Webservice和后台方法
- VS2005 使用AJAX直接调用后台方法
- jquery ajax调用asp.net 后台方法
- leetcode63. Unique Paths II
- Linux 虚拟文件系统(一)概述
- hadoop2.7.3+zookeeper3.4.6+jdk1.8+centos7的三台服务器环境部署
- 第3章 起步
- Attempt to invoke virtual method 'void android.app.ActionBar.hide()' on a null object reference
- 【Web】【Ajax】Ajax调用Aspx后台方法
- 数据库隔离级别 整理
- Spring+SpringMvc解决事务无效问题
- vue.js环境配置--vue-cli
- 四元数与欧拉角之间的换算关系
- 搜索框设计指南
- python中用matplotlib包进行简单的可视化
- 在Windows上安装Redis
- 【数据压缩】WAV PCM FORMAT