Ajax Blog 用到的幾個函數第1/3頁

來源:互聯網
上載者:User

類名:AJAX 複製代碼 代碼如下:/*類名:AJAX

建立方法:var ajaxobj=new AJAX;,如果建立失敗則返回false

屬性:method - 要求方法,字串,POST或者GET,預設為POST
   url - 請求URL,字串,預設為空白
   async - 是否非同步,true為非同步,false為同步,預設為true
   content - 請求的內容,如果要求方法為POST需要設定此屬性,預設為空白
backtext - 預設true當backtext=true時返回XMLHttp.responseText為false時返回XMLHttp.responseXML 
gettext  - 傳回值
   callback - 回呼函數,即返迴響應內容時調用的函數,預設為直接返回,回呼函數有一個參數為XMLHttpRequest對象,即定義回呼函數時要這樣:function mycallback(xmlobj)

方法:send() - 發送請求,無參數

*/

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="狀態:["+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複製代碼 代碼如下://開啟和關閉左欄
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","開啟左欄");
}
}
//開啟和關閉評論
function $PL(id,plid){
if($("rp"+id).style.display=='none'){
$("rp"+id).style.display='block';
$F("pl"+id,"隱藏評論");
replycon(id,"rp"+id);
}
else{
$("rp"+id).style.display='none';
$F("pl"+id,"查看評論");
}
}

//顯示日誌
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();
}

//取得評論內容
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();
}

//取得評論數量
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();
}

//載入發表評論表單
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();
}

//添加評論內容
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("評論已提交成功")>=0) {
//如果評論提交成功則關閉表單、重新取得評論的數量。關閉成功提示資訊
$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","請署上你的大名");
setTimeout('$CS("gberr","none")',2000);
return false;
}
if (gbemail==""){
$CS("gberr","block");
$F("gberr","請寫上你的郵箱");
setTimeout('$CS("gberr","none")',2000);
return false;
}
if (gbcon==""){
$CS("gberr","block");
$F("gberr","請發表你的意見");
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();
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.