簡介:這是dede-ajax-js應用的詳細頁面,介紹了和php,有關的知識、技巧、經驗,和一些php源碼等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=339595' scrolling='no'>
<!--
//xmlhttp和xmldom對象
var DedeXHTTP = null;
var DedeXDOM = null;
var DedeContainer = null;
var DedeShowError = false;
var DedeShowWait = false;
var DedeErrCon = "";
var DedeErrDisplay = "下載資料失敗";
var DedeWaitDisplay = "正在下載資料...";
//擷取指定ID的元素
function $DE(id) {
return document.getElementById(id);
}
//gcontainer 是儲存下載完成的內容的容器
//mShowError 是否提示錯誤資訊
//DedeShowWait 是否提示等待資訊
//mErrCon 伺服器返回什麼字串視為錯誤
//mErrDisplay 發生錯誤時顯示的資訊
//mWaitDisplay 等待時提示資訊
//預設調用 DedeAjax('divid',false,false,'','','')
function DedeAjax(gcontainer,mShowError,mShowWait,mErrCon,mErrDisplay,mWaitDisplay)
{
DedeContainer = gcontainer;
DedeShowError = mShowError;
DedeShowWait = mShowWait;
if(mErrCon!="") DedeErrCon = mErrCon;
if(mErrDisplay!="") DedeErrDisplay = mErrDisplay;
if(mErrDisplay=="x") DedeErrDisplay = "";
if(mWaitDisplay!="") DedeWaitDisplay = mWaitDisplay;
//post或get發送資料的索引值對
this.keys = Array();
this.values = Array();
this.keyCount = -1;
this.sendlang = 'gb2312';
//要求標頭類型
this.rtype = 'text';
//初始化xmlhttp
//IE6、IE5
if(window.ActiveXObject) {
try { DedeXHTTP = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) { }
if (DedeXHTTP == null) try { DedeXHTTP = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { }
}
else {
DedeXHTTP = new XMLHttpRequest();
}
//增加一個POST或GET索引值對
this.AddKeyN = function(skey,svalue) {
if(this.sendlang=='utf-8') this.AddKeyUtf8(skey, svalue);
else this.AddKey(skey, svalue);
};
this.AddKey = function(skey,svalue) {
this.keyCount++;
this.keys[this.keyCount] = skey;
svalue = svalue+'';
if(svalue != '') svalue = svalue.replace(/\+/g,'$#$');
this.values[this.keyCount] = escape(svalue);
};
//增加一個POST或GET索引值對
this.AddKeyUtf8 = function(skey,svalue) {
this.keyCount++;
this.keys[this.keyCount] = skey;
svalue = svalue+'';
if(svalue != '') svalue = svalue.replace(/\+/g,'$#$');
this.values[this.keyCount] = encodeURI(svalue);
};
//增加一個Http要求標頭索引值對
this.AddHead = function(skey,svalue) {
this.rkeyCount++;
this.rkeys[this.rkeyCount] = skey;
this.rvalues[this.rkeyCount] = svalue;
};
//清除當前對象的雜湊表參數
this.ClearSet = function() {
this.keyCount = -1;
this.keys = Array();
this.values = Array();
this.rkeyCount = -1;
this.rkeys = Array();
this.rvalues = Array();
};
DedeXHTTP.onreadystatechange = function() {
//在IE6中不管阻斷或非同步模式都會執行這個事件的
if(DedeXHTTP.readyState == 4){
if(DedeXHTTP.status == 200)
{
if(DedeXHTTP.responseText!=DedeErrCon) {
DedeContainer.innerHTML = DedeXHTTP.responseText;
}
else {
if(DedeShowError) DedeContainer.innerHTML = DedeErrDisplay;
}
DedeXHTTP = null;
}
else { if(DedeShowError) DedeContainer.innerHTML = DedeErrDisplay; }
}
else { if(DedeShowWait) DedeContainer.innerHTML = DedeWaitDisplay; }
};
//檢測阻斷模式的狀態
this.BarrageStat = function() {
if(DedeXHTTP==null) return;
if(typeof(DedeXHTTP.status)!=undefined && DedeXHTTP.status == 200)
{
if(DedeXHTTP.responseText!=DedeErrCon) {
DedeContainer.innerHTML = DedeXHTTP.responseText;
}
else {
if(DedeShowError) DedeContainer.innerHTML = DedeErrDisplay;
}
}
};
//發送http要求標頭
this.SendHead = function()
{
//發送使用者自行設定的要求標頭
if(this.rkeyCount!=-1)
{
for(var i = 0;i<=this.rkeyCount;i++)
{
DedeXHTTP.setRequestHeader(this.rkeys[i],this.rvalues[i]);
}
}
if(this.rtype=='binary'){
DedeXHTTP.setRequestHeader("Content-Type","multipart/form-data");
}else{
DedeXHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
};
//用Post方式發送資料
this.SendPost = function(purl) {
var pdata = "";
var i=0;
this.state = 0;
DedeXHTTP.open("POST", purl, true);
this.SendHead();
//post資料
if(this.keyCount!=-1)
{
for(;i<=this.keyCount;i++)
{
if(pdata=="") pdata = this.keys[i]+'='+this.values[i];
else pdata += "&"+this.keys[i]+'='+this.values[i];
}
}
DedeXHTTP.send(pdata);
};
//用GET方式發送資料
this.SendGet = function(purl) {
var gkey = "";
var i=0;
this.state = 0;
//get參數
if(this.keyCount!=-1)
{
for(;i<=this.keyCount;i++)
{
if(gkey=="") gkey = this.keys[i]+'='+this.values[i];
else gkey += "&"+this.keys[i]+'='+this.values[i];
}
if(purl.indexOf('?')==-1) purl = purl + '?' + gkey;
else purl = purl + '&' + gkey;
}
DedeXHTTP.open("GET", purl, true);
this.SendHead();
DedeXHTTP.send(null);
};
//用GET方式發送資料,阻塞模式
this.SendGet2 = function(purl) {
var gkey = "";
var i=0;
this.state = 0;
//get參數
if(this.keyCount!=-1)
{
for(;i<=this.keyCount;i++)
{
if(gkey=="") gkey = this.keys[i]+'='+this.values[i];
else gkey += "&"+this.keys[i]+'='+this.values[i];
}
if(purl.indexOf('?')==-1) purl = purl + '?' + gkey;
else purl = purl + '&' + gkey;
}
DedeXHTTP.open("GET", purl, false);
this.SendHead();
DedeXHTTP.send(null);
//firefox中直接檢測XHTTP狀態
this.BarrageStat();
};
//用Post方式發送資料
this.SendPost2 = function(purl) {
var pdata = "";
var i=0;
this.state = 0;
DedeXHTTP.open("POST", purl, false);
this.SendHead();
//post資料
if(this.keyCount!=-1)
{
for(;i<=this.keyCount;i++)
{
if(pdata=="") pdata = this.keys[i]+'='+this.values[i];
else pdata += "&"+this.keys[i]+'='+this.values[i];
}
}
DedeXHTTP.send(pdata);
//firefox中直接檢測XHTTP狀態
this.BarrageStat();
};
} // End Class DedeAjax
//初始化xmldom
function InitXDom() {
if(DedeXDOM!=null) return;
var obj = null;
// Gecko、Mozilla、Firefox
if (typeof(DOMParser) != "undefined") {
var parser = new DOMParser();
obj = parser.parseFromString(xmlText, "text/xml");
}
// IE
else {
try { obj = new ActiveXObject("MSXML2.DOMDocument");} catch (e) { }
if (obj == null) try { obj = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) { }
}
DedeXDOM = obj;
};
//讀寫cookie函數
function GetCookie(c_name)
{
if (document.cookie.length > 0)
{
c_start = document.cookie.indexOf(c_name + "=")
if (c_start != -1)
{
c_start = c_start + c_name.length + 1;
c_end = document.cookie.indexOf(";",c_start);
if (c_end == -1)
{
c_end = document.cookie.length;
}
return unescape(document.cookie.substring(c_start,c_end));
}
}
return null
}
function SetCookie(c_name,value,expiredays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使設定的有效時間正確。增加toGMTString()
}
//ajax調用
function ajax(id,url)
{
var taget_obj = document.getElementById(id);
myajax = new DedeAjax(taget_obj,false,false,'','','');
myajax.SendGet2(url);
DedeXHTTP = null;
}
-->
<div id="ajax1"><a href="javascript:ajax('ajax1','xx.php')">AJAX測試</a></div>
愛J2EE關注Java邁克爾傑克遜視頻站JSON線上工具
http://biancheng.dnbcw.info/php/339595.html pageNo:8