实现一个JavaScript验证的Asp.net Helper
2009-09-29 00:00:00 来源:WEB开发网扩展Ajax功能
Validator.prototype.Ajax = function(url,params)
{
var result = $.ajax({
url: url,
async: false,
data:__CreatePostData(params)
}).responseText;
if($(result).find('Exception').text())
this.Success = false;
else
this.Success = true;
}
function __CreatePostData(expression)
{
var param = new Object();
if(expression != null && expression !='')
{
var properties = expression.split('&');
var namevalue,execute;
for(i =0;i<properties.length;i++)
{
namevalue = properties[i].split('=');
if(namevalue.length ==2)
{
if(namevalue[1].indexOf('#') >=0)
{
execute ='param.' + namevalue[0]+'=$("'+ namevalue[1]+'").val()';
}
else
{
execute ='param.' + namevalue[0]+'="'+ namevalue[1]+'"';
}
eval(execute);
}
}
}
param.PostTime = new Date().toString();
return param;
}
Code
public Validator Ajax(string url, string data, string errmsg, string successmsg)
{
OutputScript(o => { WriteLine("tt_{0}.Ajax('{1}','{2}');", GetHashCode(), url,data); }, errmsg, successmsg);
return this;
}
Tags:实现 一个 JavaScript
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接