Ajax Blog 用到的幾個(gè)函數(shù)第1/3頁(yè)
更新時(shí)間:2006年10月03日 00:00:00 作者:
類(lèi)名:AJAX
/*類(lèi)名:AJAX
創(chuàng)建方法:var ajaxobj=new AJAX;,如果創(chuàng)建失敗則返回false
屬性:method - 請(qǐng)求方法,字符串,POST或者GET,默認(rèn)為POST
url - 請(qǐng)求URL,字符串,默認(rèn)為空
async - 是否異步,true為異步,false為同步,默認(rèn)為true
content - 請(qǐng)求的內(nèi)容,如果請(qǐng)求方法為POST需要設(shè)定此屬性,默認(rèn)為空
backtext - 默認(rèn)true當(dāng)backtext=true時(shí)返回XMLHttp.responseText為false時(shí)返回XMLHttp.responseXML
gettext - 返回值
callback - 回調(diào)函數(shù),即返回響應(yīng)內(nèi)容時(shí)調(diào)用的函數(shù),默認(rèn)為直接返回,回調(diào)函數(shù)有一個(gè)參數(shù)為XMLHttpRequest對(duì)象,即定義回調(diào)函數(shù)時(shí)要這樣:function mycallback(xmlobj)
方法:send() - 發(fā)送請(qǐng)求,無(wú)參數(shù)
*/
function AJAX() {
var XMLHttp = false;
var ObjSelf;
ObjSelf=this;
try { XMLHttp=new XMLHttpRequest; }
catch(e) {
try { XMLHttp=new ActiveXObject("MSXML2.XMLHttp"); }
catch(e2) {
try { XMLHttp=new ActiveXObject("Microsoft.XMLHttp"); }
catch(e3) { XMLHttp=false; }
}
}
if (!XMLHttp) return false;
this.method="POST";
this.url=""
this.url += (this.url.indexOf("?") >= 0) ? "&nowtime=" + new Date().getTime():"?nowtime=" + new Date().getTime();
this.async=true;
this.data="";
ObjSelf.loadid=""
this.backtext=true
this.callback=function() {return;}
this.send=function() {
if(!this.method||!this.url||!this.async) return false;
XMLHttp.open (this.method, this.url, this.async);
if(this.method=="POST"){
XMLHttp.setRequestHeader("Content-Length",(this.data).length);
XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
XMLHttp.onreadystatechange=function() {
if(XMLHttp.readyState==4) {
//alert(ObjSelf.loadid);
if (ObjSelf.loadid!="") $CS(ObjSelf.loadid,"none");
//window.status="";
if(XMLHttp.status==200) {
ObjSelf.callback();
}
}
else {
if (ObjSelf.loadid!="") $CS(ObjSelf.loadid,"block");
//window.status="狀態(tài):["+XMLHttp.readyState+"]正在加載......";
}
}
if(this.method=="POST") XMLHttp.send(this.data);
else XMLHttp.send(null);
}
this.gettext=function(){
if(XMLHttp.readyState==4) {
if(XMLHttp.status==200) {
if (this.backtext==true){
return XMLHttp.responseText;
}else{
return XMLHttp.responseXML;
}
}
}
}
}
blog.js
//打開(kāi)和關(guān)閉左欄
function $SHleft(id){
if($(id).style.display=='none'){
$(id).style.display='block';
$("content").style.width='550px';
$F("sh","隱藏左欄");
}
else{
$(id).style.display='none';
$("content").style.width='750px';
$F("sh","打開(kāi)左欄");
}
}
//打開(kāi)和關(guān)閉評(píng)論
function $PL(id,plid){
if($("rp"+id).style.display=='none'){
$("rp"+id).style.display='block';
$F("pl"+id,"隱藏評(píng)論");
replycon(id,"rp"+id);
}
else{
$("rp"+id).style.display='none';
$F("pl"+id,"查看評(píng)論");
}
}
//顯示日志
function show(id,pageid,rq){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=show&sid="+id+"&rq="+escape(rq)+"&page="+pageid;
ajaxobj.callback=function(){
$F("bkcon",ajaxobj.gettext());
}
ajaxobj.send();
}
//顯示日志分類(lèi)列表
function board(){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=board";
ajaxobj.callback=function(){
$F("blogcon",ajaxobj.gettext());
}
ajaxobj.send();
}
//取得評(píng)論內(nèi)容
function replycon(rid,rpid){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=replycon&rid="+rid;
ajaxobj.callback=function(){
$F(rpid,ajaxobj.gettext());
}
ajaxobj.send();
}
//取得評(píng)論數(shù)量
function plnum(rid){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=plnum&rid="+rid;
ajaxobj.callback=function(){
$F("plnum"+rid,ajaxobj.gettext());
}
ajaxobj.send();
}
//加載發(fā)表評(píng)論表單
function rform(rid){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=rform&rid="+rid;
ajaxobj.callback=function(){
$F("plform"+rid,ajaxobj.gettext());
}
ajaxobj.send();
}
//添加評(píng)論內(nèi)容
function savepl(rid){
var ajaxobj=new AJAX();
ajaxobj.method="POST";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=savepl&";
ajaxobj.data="rid="+rid+"&username="+escape($("username"+rid).value)+"&con="+escape($("con"+rid).value);
ajaxobj.callback=function(){
$F("tjpl"+rid,ajaxobj.gettext());
if (ajaxobj.gettext().indexOf("評(píng)論已提交成功")>=0) {
//如果評(píng)論提交成功則關(guān)閉表單、重新取得評(píng)論的數(shù)量。關(guān)閉成功提示信息
$CS("rform"+rid,"none");
plnum(rid);
pltjid="pltjsuc"+rid;
setTimeout('$CS(pltjid,"none")',1000);
}
}
ajaxobj.send();
}
//顯示日歷
function rl(ReqDate){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=rl&ReqDate="+ReqDate;
ajaxobj.callback=function(){
$F("calendarcon",ajaxobj.gettext());
}
ajaxobj.send();
}
//顯示留言表單
function gb(){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=gb";
ajaxobj.callback=function(){
$F("gbform",ajaxobj.gettext());
}
ajaxobj.send();
}
//提交留言
function savegb(){
var gbusername=$("gbusername").value;
var gbemail=$("gbemail").value;
var gbcon=$("gbcon").value;
//alert($("gbusername").value);
//alert($("gbemail").value);
//alert($("gbcon").value);
//return false;
if (gbusername==""){
$CS("gberr","block");
$F("gberr","請(qǐng)署上你的大名");
setTimeout('$CS("gberr","none")',2000);
return false;
}
if (gbemail==""){
$CS("gberr","block");
$F("gberr","請(qǐng)寫(xiě)上你的郵箱");
setTimeout('$CS("gberr","none")',2000);
return false;
}
if (gbcon==""){
$CS("gberr","block");
$F("gberr","請(qǐng)發(fā)表你的意見(jiàn)");
setTimeout('$CS("gberr","none")',2000);
return false;
}
var ajaxobj=new AJAX();
ajaxobj.method="POST";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=addgb&";
ajaxobj.data="username="+escape(gbusername)+"&email="+escape(gbemail)+"&con="+escape(gbcon);
ajaxobj.send();
ajaxobj.callback=function(){
if (ajaxobj.gettext().indexOf("成功")>=0) {
$SHwin("gb");
showgb(1);
}
}
}
//顯示留言
function showgb(pageid){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=showgb&page="+pageid;
ajaxobj.callback=function(){
$F("bkcon",ajaxobj.gettext());
}
ajaxobj.send();
}
復(fù)制代碼 代碼如下:
/*類(lèi)名:AJAX
創(chuàng)建方法:var ajaxobj=new AJAX;,如果創(chuàng)建失敗則返回false
屬性:method - 請(qǐng)求方法,字符串,POST或者GET,默認(rèn)為POST
url - 請(qǐng)求URL,字符串,默認(rèn)為空
async - 是否異步,true為異步,false為同步,默認(rèn)為true
content - 請(qǐng)求的內(nèi)容,如果請(qǐng)求方法為POST需要設(shè)定此屬性,默認(rèn)為空
backtext - 默認(rèn)true當(dāng)backtext=true時(shí)返回XMLHttp.responseText為false時(shí)返回XMLHttp.responseXML
gettext - 返回值
callback - 回調(diào)函數(shù),即返回響應(yīng)內(nèi)容時(shí)調(diào)用的函數(shù),默認(rèn)為直接返回,回調(diào)函數(shù)有一個(gè)參數(shù)為XMLHttpRequest對(duì)象,即定義回調(diào)函數(shù)時(shí)要這樣:function mycallback(xmlobj)
方法:send() - 發(fā)送請(qǐng)求,無(wú)參數(shù)
*/
function AJAX() {
var XMLHttp = false;
var ObjSelf;
ObjSelf=this;
try { XMLHttp=new XMLHttpRequest; }
catch(e) {
try { XMLHttp=new ActiveXObject("MSXML2.XMLHttp"); }
catch(e2) {
try { XMLHttp=new ActiveXObject("Microsoft.XMLHttp"); }
catch(e3) { XMLHttp=false; }
}
}
if (!XMLHttp) return false;
this.method="POST";
this.url=""
this.url += (this.url.indexOf("?") >= 0) ? "&nowtime=" + new Date().getTime():"?nowtime=" + new Date().getTime();
this.async=true;
this.data="";
ObjSelf.loadid=""
this.backtext=true
this.callback=function() {return;}
this.send=function() {
if(!this.method||!this.url||!this.async) return false;
XMLHttp.open (this.method, this.url, this.async);
if(this.method=="POST"){
XMLHttp.setRequestHeader("Content-Length",(this.data).length);
XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
XMLHttp.onreadystatechange=function() {
if(XMLHttp.readyState==4) {
//alert(ObjSelf.loadid);
if (ObjSelf.loadid!="") $CS(ObjSelf.loadid,"none");
//window.status="";
if(XMLHttp.status==200) {
ObjSelf.callback();
}
}
else {
if (ObjSelf.loadid!="") $CS(ObjSelf.loadid,"block");
//window.status="狀態(tài):["+XMLHttp.readyState+"]正在加載......";
}
}
if(this.method=="POST") XMLHttp.send(this.data);
else XMLHttp.send(null);
}
this.gettext=function(){
if(XMLHttp.readyState==4) {
if(XMLHttp.status==200) {
if (this.backtext==true){
return XMLHttp.responseText;
}else{
return XMLHttp.responseXML;
}
}
}
}
}
blog.js
復(fù)制代碼 代碼如下:
//打開(kāi)和關(guān)閉左欄
function $SHleft(id){
if($(id).style.display=='none'){
$(id).style.display='block';
$("content").style.width='550px';
$F("sh","隱藏左欄");
}
else{
$(id).style.display='none';
$("content").style.width='750px';
$F("sh","打開(kāi)左欄");
}
}
//打開(kāi)和關(guān)閉評(píng)論
function $PL(id,plid){
if($("rp"+id).style.display=='none'){
$("rp"+id).style.display='block';
$F("pl"+id,"隱藏評(píng)論");
replycon(id,"rp"+id);
}
else{
$("rp"+id).style.display='none';
$F("pl"+id,"查看評(píng)論");
}
}
//顯示日志
function show(id,pageid,rq){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=show&sid="+id+"&rq="+escape(rq)+"&page="+pageid;
ajaxobj.callback=function(){
$F("bkcon",ajaxobj.gettext());
}
ajaxobj.send();
}
//顯示日志分類(lèi)列表
function board(){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=board";
ajaxobj.callback=function(){
$F("blogcon",ajaxobj.gettext());
}
ajaxobj.send();
}
//取得評(píng)論內(nèi)容
function replycon(rid,rpid){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=replycon&rid="+rid;
ajaxobj.callback=function(){
$F(rpid,ajaxobj.gettext());
}
ajaxobj.send();
}
//取得評(píng)論數(shù)量
function plnum(rid){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=plnum&rid="+rid;
ajaxobj.callback=function(){
$F("plnum"+rid,ajaxobj.gettext());
}
ajaxobj.send();
}
//加載發(fā)表評(píng)論表單
function rform(rid){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=rform&rid="+rid;
ajaxobj.callback=function(){
$F("plform"+rid,ajaxobj.gettext());
}
ajaxobj.send();
}
//添加評(píng)論內(nèi)容
function savepl(rid){
var ajaxobj=new AJAX();
ajaxobj.method="POST";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=savepl&";
ajaxobj.data="rid="+rid+"&username="+escape($("username"+rid).value)+"&con="+escape($("con"+rid).value);
ajaxobj.callback=function(){
$F("tjpl"+rid,ajaxobj.gettext());
if (ajaxobj.gettext().indexOf("評(píng)論已提交成功")>=0) {
//如果評(píng)論提交成功則關(guān)閉表單、重新取得評(píng)論的數(shù)量。關(guān)閉成功提示信息
$CS("rform"+rid,"none");
plnum(rid);
pltjid="pltjsuc"+rid;
setTimeout('$CS(pltjid,"none")',1000);
}
}
ajaxobj.send();
}
//顯示日歷
function rl(ReqDate){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=rl&ReqDate="+ReqDate;
ajaxobj.callback=function(){
$F("calendarcon",ajaxobj.gettext());
}
ajaxobj.send();
}
//顯示留言表單
function gb(){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=gb";
ajaxobj.callback=function(){
$F("gbform",ajaxobj.gettext());
}
ajaxobj.send();
}
//提交留言
function savegb(){
var gbusername=$("gbusername").value;
var gbemail=$("gbemail").value;
var gbcon=$("gbcon").value;
//alert($("gbusername").value);
//alert($("gbemail").value);
//alert($("gbcon").value);
//return false;
if (gbusername==""){
$CS("gberr","block");
$F("gberr","請(qǐng)署上你的大名");
setTimeout('$CS("gberr","none")',2000);
return false;
}
if (gbemail==""){
$CS("gberr","block");
$F("gberr","請(qǐng)寫(xiě)上你的郵箱");
setTimeout('$CS("gberr","none")',2000);
return false;
}
if (gbcon==""){
$CS("gberr","block");
$F("gberr","請(qǐng)發(fā)表你的意見(jiàn)");
setTimeout('$CS("gberr","none")',2000);
return false;
}
var ajaxobj=new AJAX();
ajaxobj.method="POST";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=addgb&";
ajaxobj.data="username="+escape(gbusername)+"&email="+escape(gbemail)+"&con="+escape(gbcon);
ajaxobj.send();
ajaxobj.callback=function(){
if (ajaxobj.gettext().indexOf("成功")>=0) {
$SHwin("gb");
showgb(1);
}
}
}
//顯示留言
function showgb(pageid){
var ajaxobj=new AJAX();
ajaxobj.method="GET";
ajaxobj.loadid="loadnews";
ajaxobj.url="lib.asp?action=showgb&page="+pageid;
ajaxobj.callback=function(){
$F("bkcon",ajaxobj.gettext());
}
ajaxobj.send();
}
相關(guān)文章
js中獲取鍵盤(pán)按下鍵值event.keyCode、event.charCode和event.which的兼容性詳解
這篇文章主要給大家介紹了關(guān)于Javascript中獲取鍵盤(pán)按下鍵值event.keyCode、event.charCode和event.which的兼容性的相關(guān)資料,文中介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-03-03JavaScript中實(shí)現(xiàn)最高效的數(shù)組亂序方法
這篇文章主要介紹了JavaScript中實(shí)現(xiàn)最高效的數(shù)組亂序方法,數(shù)組亂序的意思是,把數(shù)組內(nèi)的所有元素排列順序打亂,需要的朋友可以參考下2014-10-10經(jīng)典的解除許多網(wǎng)站無(wú)法復(fù)制文字的絕招
經(jīng)典的解除許多網(wǎng)站無(wú)法復(fù)制文字的絕招...2006-12-12?js中toString()函數(shù)與valueOf()函數(shù)使用與區(qū)別
在等于運(yùn)算符中,如果比較的內(nèi)容包含對(duì)象類(lèi)型數(shù)據(jù),則會(huì)涉及隱式轉(zhuǎn)換,那么就會(huì)調(diào)用toString()函數(shù)和valueOf()函數(shù),本文主要介紹了?js中toString()函數(shù)與valueOf()函數(shù)使用與區(qū)別,感興趣的可以了解一下2022-04-04javascript實(shí)現(xiàn)電商放大鏡效果
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)電商放大鏡效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11javascript實(shí)現(xiàn)帶節(jié)日和農(nóng)歷的日歷特效
這篇文章主要介紹了javascript實(shí)現(xiàn)帶節(jié)日和農(nóng)歷的日歷特效,效果十分棒,需要的朋友可以參考下2015-02-02