Ajax的前后台封装
2021-04-19 13:25
标签:script tpc add obj 后台 error roo nbsp converter 1.get传值(同步) function ajaxHandler(className, functionName, data, successFunc, errorFunc) { 2.post传值(同步) function ajaxPostHandler(className, functionName, data, successFunc, errorFunc) { 3.post传值(异步) function ajaxPostHandlersync(className, functionName, data, successFunc, errorFunc) { 4.get传值(异步) 后台: public override void Process_Request(HttpContext context) public dynamic ConvertJson(string json) Ajax的前后台封装 标签:script tpc add obj 后台 error roo nbsp converter 原文地址:https://www.cnblogs.com/wangSoft/p/12269894.html
var path = getRootPath();
var Para = "?className=" + className + "&functionName=" + functionName + "&ran=" + new Date().getUTCMilliseconds();
$.ajax({
type: "GET",
url: path + "/Handler/HandlerAll.ashx" + Para,
data: data,
success: function (datd) {
successFunc(datd);
},
error: function () {
if (arguments.length == 5) {
errorFunc();
}
}
});
}
var path = getRootPath();
var Para = "?className=" + className + "&functionName=" + functionName + "&ran=" + new Date().getUTCMilliseconds();
$.ajax({
type: "POST",
url: path + "/Handler/HandlerAll.ashx" + Para,
data: data,
success: function (datd) {
successFunc(datd);
},
error: function () {
if (arguments.length == 5) {
errorFunc();
}
}
});
}
var path = getRootPath();
var Para = "?className=" + className + "&functionName=" + functionName + "&ran=" + new Date().getUTCMilliseconds();
$.ajax({
type: "POST",
async: false,
url: path + "/Handler/HandlerAll.ashx" + Para,
data: data,
success: function (datd) {
successFunc(datd);
},
error: function () {
if (arguments.length == 5) {
errorFunc();
}
}
});
}
function ajaxHandlerasync(className, functionName, data, successFunc, errorFunc) {
var path = getRootPath();
var Para = "?className=" + className + "&functionName=" + functionName + "&ran=" + new Date().getUTCMilliseconds();
$.ajax({
type: "GET",
async: false,
url: path + "/Handler/HandlerAll.ashx" + Para,
data: data,
success: function (datd) {
successFunc(datd);
},
error: function () {
if (arguments.length == 5) {
errorFunc();
}
}
});
}
{
string functionName = context.Request.QueryString["functionName"];
string ClassName = context.Request.QueryString["className"];
Type type = Type.GetType(ClassName);
if (functionName.Trim() != string.Empty)
{
List
{
//JavaScriptSerializer jss = new JavaScriptSerializer();
//jss.RegisterConverters(new JavaScriptConverter[] { new DynamicJsonConverter() });
//dynamic dy = jss.Deserialize(json, typeof(object)) as dynamic;
var serializer = new JavaScriptSerializer();
serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
dynamic dy = serializer.Deserialize(json, typeof(object));
return dy;
}