ASP.NET WebForm也可以这样用Ajax
作者:网络转载 发布时间:[ 2013/4/2 9:53:36 ] 推荐标签:
第三个参数是操作成功之后执行执行的回调方法,与c#中的委托一个道理。
以下为这个简单JS库的代码:
var PowerAjax = function () { }
PowerAjax.__Private = function () { }
// 进行异步操作
PowerAjax.AsyncAjax = function (methodName, paramArray, success) {
PowerAjax.__Private.Ajax(methodName, paramArray, success, true);
}
// 进行的是同步操作
PowerAjax.SyncAjax = function (methodName, paramArray, success) {
PowerAjax.__Private.Ajax(methodName, paramArray, success, false);
}
PowerAjax.__Private.Ajax = function (methodName, paramArray, success, isAsync) {
var data = {};
switch (paramArray.length) {
case 0:
data = { 'isAjaxRequest': true, 'MethodName': methodName };
break;
case 1:
data = { 'isAjaxRequest': true, 'MethodName': methodName, "param0": paramArray[0] };
break;
case 2:
data = { 'isAjaxRequest': true, 'MethodName': methodName, "param0": paramArray[0], "param1": paramArray[1] };
break;
case 3:
data = { 'isAjaxRequest': true, 'MethodName': methodName, "param0": paramArray[0], "param1": paramArray[1], "param2": paramArray[2] };
break;
case 4:
data = { 'isAjaxRequest': true, 'MethodName': methodName, "param0": paramArray[0], "param1": paramArray[1], "param2": paramArray[2], "param3": paramArray[3] };
break;
case 5:
data = { 'isAjaxRequest': true, 'MethodName': methodName, "param0": paramArray[0], "param1": paramArray[1], "param2": paramArray[2], "param3": paramArray[3], "param4": paramArray[4] };
break;
}
var url = document.location.href;
$.ajax({
type: "post",
url: url,
data: data,
async: isAsync,
datatype: "json",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
success: function (response) {
success(response);
},
error: function (response) {
if (response.status == 500) {
var errorMessage = response.responseText;
var errorTitle = errorMessage.substring(errorMessage.indexOf("<title>") + 7, errorMessage.indexOf("</title>"))
throw new Error("服务器内部错误:" + errorTitle);
}
}
});
}
5、更改Default.aspx.cs的继承页面为AjaxBasePage
public partial class _Default : AjaxBasePage
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11