ajax js daima

// JavaScriptDocument
function $(id)
{
return document.getElementById(id);
}
function echo(obj,html)
{
$(obj).innerHTML
= html;
}
function fopen(obj)
{
$(obj).style.display
= "" ;
}
function fclose(obj)
{
$(obj).style.display
= " none " ;
}
function lTrim(str)
{
if (str.charAt( 0 ) == " " )
{
// 如果字串左边第一个字符为空格
str = str.slice( 1 ); // 将空格从字串中去掉
// 这一句也可改成str=str.substring(1,str.length);
str = lTrim(str); // 递归调用
}
return str;
}

// 去掉字串右边的空格
function rTrim(str)
{
var iLength;

iLength
= str.length;
if (str.charAt(iLength - 1 ) == " " )
{
// 如果字串右边第一个字符为空格
str = str.slice( 0 ,iLength - 1 ); // 将空格从字串中去掉
// 这一句也可改成str=str.substring(0,iLength-1);
str = rTrim(str); // 递归调用
}
return str;
}

// 去掉字串两边的空格
function trim(str)
{
return lTrim(rTrim(str));
}
function sck(s)
{
return s.replace( / / g, " [br] " );
// s=s.replace(chr(13)&chr(23),"<br/>");
// returns;
}
function f(obj)
{
return trim(eval( " document.forms[0]. " + obj + " .value " ));
// returntrim($(obj).value);
}
function setf(obj)
{
return eval( " document.forms[0]. " + obj + " .focus(); " );
}
function show(obj)
{
var s = $(obj).style;
s.display
= s.display == " none " ? "" : " none " ;
}
function echo(obj,html)
{
$(obj).innerHTML
= html;
}
function createxmlhttp()
{
var xmlhttp = false ;
try {
xmlhttp
= new ActiveXObject( " Msxml2.XMLHTTP " );
}
catch (e){
try {
xmlhttp
= new ActiveXObject( " Microsoft.XMLHTTP " );
}
catch (e){
xmlhttp
= false ;
}
}
if ( ! xmlhttp && typeof XMLHttpRequest != ' undefined ' ){
xmlhttp
= new XMLHttpRequest();
if (xmlhttp.overrideMimeType){ // 设置MiME类别
xmlhttp.overrideMimeType( ' text/xml ' );
}
}

return xmlhttp;
}
function getnum(url,obj)
{
// varb="";
var xmlhttp = createxmlhttp();
if ( ! xmlhttp)
{
alert(
" 你的浏览器不支持XMLHTTP!! " );
return ;
}
xmlhttp.onreadystatechange
= requestdata;
xmlhttp.open(
" GET " ,url, true );
xmlhttp.send(
null );
function requestdata(){
if (xmlhttp.readyState == 4 )
{
if (xmlhttp.status == 200 )
{
$(obj).value
= xmlhttp.responseText;
}
}
}
}
function getdata(url,obj1,obj2)
{

var xmlhttp = createxmlhttp();
if ( ! xmlhttp)
{
alert(
" 你的浏览器不支持XMLHTTP!! " );
return ;
}
xmlhttp.onreadystatechange
= requestdata;
xmlhttp.open(
" GET " ,url, true );
xmlhttp.send(
null );
function requestdata()
{

fopen(obj1);
echo(obj1,
" 正在加载数据,请稍等...... " );
if (xmlhttp.readyState == 4 )
{
if (xmlhttp.status == 200 )
{
if (obj1 != obj2){fclose(obj1);};
echo(obj2,xmlhttp.responseText);

}
}

}
}
function postdata(url,obj,data)
{
var xmlhttp = createxmlhttp();
if ( ! xmlhttp)
{
alert(
" 你的浏览器不支持XMLHTTP!! " );
return ;
}
xmlhttp.open(
" POST " ,url, true );
xmlhttp.onreadystatechange
= requestdata;
xmlhttp.setRequestHeader(
" Content-Type " , " application/x-www-form-urlencoded " );
xmlhttp.send(data);
function requestdata()
{
fopen(obj);
echo(obj,
" 正在提交数据,请稍等...... " );
// alert(xmlhttp.readyState);
if (xmlhttp.readyState == 4 )
{
// alert(xmlhttp.status);
if (xmlhttp.status == 200 )
{
echo(obj,xmlhttp.responseText);
}
}
}
}
function checkform(obj,id)
{
if (f( " user " ) == "" )
{
alert(
" 请留下您的大名!! " );
setf(
" user " );
return false ;
}
if (f( " user " ).length > 10 && f( " user " ) < 2 )
{
alert(
" 姓名长度只能在2-10位之间!! " );
}
if (f( " title " ) == "" )
{
alert(
" 请填写留言标题!! " );
setf(
" title " );
return false ;
}
if (f( " title " ).length > 50 )
{
alert(
" 对不起标题太长了!! " );
setf(
" title " );
return false ;
}
if (f( " content " ) == "" )
{
alert(
" 留言内容不能为空!! " );
setf(
" content " );
return false ;
}
data
= " user= " + escape(f( " user " )) + " &title= " + escape(f( " title " )) + " &content= " + escape(document.forms[ 0 ].content.value) + " &reply= " + escape(f( " reply " ));
// alert(data);
// data="content="+escape(sck(f("content")));
if (obj == " add " )
{
// alert(obj);
postdata( " file.asp?action=addsave " , " contentdata " ,data);
}
else if (obj == " reply " )
{
postdata(
" file.asp?action=replysave " , " contentadmin " + id,data);
}
return true ;
}
function adminlogin()
{
if ($( " adminuser " ).value == "" )
{
alert(
" 管理帐号不能为空! " );
$(
" adminuser " ).focus();
return false ;
}
if ($( " adminpwd " ).value == "" )
{
alert(
" 管理密码不能为空! " );
$(
" adminpwd " ).focus();
return false ;
}
data
= " adminuser= " + escape($( " adminuser " ).value) + " &adminpwd= " + escape($( " adminpwd " ).value);
postdata(
" file.asp?action=checkadmin " , " loginlist " ,data);
return true ;
}
function adreset()
{
$(
" adminuser " ).value = "" ;
$(
" adminpwd " ).value = "" ;
}
function linktool()
{
if ($( " linktool " ).innerHTML == " 自助链接 " )
{
$(
" linktool " ).innerHTML = " 友情链接 " ;
getdata(
" list.asp?action=addlink " , " linklist " , " linklist " );

}
else
{

$(
" linktool " ).innerHTML = " 自助链接 " ;
getdata(
" list.asp?action=linklist " , " linklist " , " linklist " );
}
}
function addlink()
{
if ($( " home " ).value == "" )
{
alert(
" 网站名称不能为空 " );
$(
" home " ).focus();
return false ;
}
if ($( " url " ).value == "" )
{
alert(
" 网站地址不能为空! " );
$(
" url " ).focus();
return false ;
}
data
= " home= " + escape($( " home " ).value) + " &url= " + escape($( " url " ).value);
postdata(
" list.asp?action=linksave " , " linklist " ,data);
return true ;
}
function linkreset()
{
$(
" home " ).value = "" ;
$(
" url " ).value = "" ;
}
function updatepwd()
{
if (f( " user " ) == "" )
{
alert(
" 请输入管理帐号! " );
setf(
" user " );
return false ;
}
if (f( " npwd " ) == "" )
{
alert(
" 请输入管理密码! " );
setf(
" npwd " );
return false ;
}
if (f( " npwd " ) != f( " npwd1 " ))
{
alert(
" 新密码和确认密码不一样!! " );
setf(
" npwd " );
return false ;
}
data
= " user= " + escape(f( " user " )) + " &pwd= " + escape(f( " npwd " ));
postdata(
" list.asp?action=savepwd " , " contentdata " ,data);
return true ;
}
function updateinfo()
{
if (f( " gonggao " ) == "" )
{
alert(
" 公告内容不能为空! " );
setf(
" gonggao " );
return false ;
}
if (f( " foot " ) == "" )
{
alert(
" 版权信息不能为空! " );
setf(
" foot " );
return false ;
}
data
= " news= " + escape(document.forms[ 0 ].gonggao.value) + " &foot= " + escape(document.forms[ 0 ].foot.value);
postdata(
" list.asp?action=infosave " , " contentdata " ,data);
return true ;
}

你可能感兴趣的:(Ajax,浏览器,F#,公告,asp)