Ajax Blog 用到的幾個(gè)函數(shù)第1/3頁(yè)
更新時(shí)間:2006年10月03日 00:00:00 作者:
類名:AJAX
/*類名: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();
}
//顯示日志分類列表
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)寫上你的郵箱");
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ù)制代碼 代碼如下:
/*類名: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();
}
//顯示日志分類列表
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)寫上你的郵箱");
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)文章
javascript 在網(wǎng)頁(yè)中的運(yùn)用(asp.net)
javascript在網(wǎng)頁(yè)中的運(yùn)用實(shí)現(xiàn),需要的朋友可以參考下。2009-11-11
JS實(shí)現(xiàn)簡(jiǎn)單的二元方程計(jì)算器功能示例
這篇文章主要介紹了JS實(shí)現(xiàn)簡(jiǎn)單的二元方程計(jì)算器功能,涉及javascript數(shù)學(xué)運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-01-01
echarts圖表無(wú)數(shù)據(jù)/空數(shù)據(jù)如何展示"暫無(wú)數(shù)據(jù)"
在開(kāi)發(fā)echarts的時(shí)候我們不得不考慮數(shù)據(jù)為空的情況,其實(shí)有很多種解決辦法,下面這篇文章主要給大家介紹了關(guān)于echarts圖表無(wú)數(shù)據(jù)/空數(shù)據(jù)如何展示“暫無(wú)數(shù)據(jù)”的相關(guān)資料,需要的朋友可以參考下2022-10-10
原生javascript實(shí)現(xiàn)拖動(dòng)元素示例代碼
首先改變被拖動(dòng)元素的布局屬性,接著捕捉鼠標(biāo)事件,當(dāng)觸發(fā)mousedown時(shí),記錄下當(dāng)前鼠標(biāo)在元素中的相對(duì)位置,接著處理mousemove事件2014-09-09
擴(kuò)展js對(duì)象數(shù)組的OrderByAsc和OrderByDesc方法實(shí)現(xiàn)思路
js的擴(kuò)展方法是基于原型的,如Array.prototype.XXXX就是給Array擴(kuò)展XXX方法,然后數(shù)組都能使用這個(gè)方法了,在對(duì)象數(shù)組里面經(jīng)常有根據(jù)屬性來(lái)進(jìn)行排序的,升序,降序的,下面與大家分享自己寫的一個(gè)2013-05-05
js類型轉(zhuǎn)換與引用類型詳解(Boolean_Number_String)
本篇文章主要是對(duì)js中的類型轉(zhuǎn)換與引用類型(Boolean_Number_String)進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-03-03

