Ajax實現(xiàn)評論提交
更新時間:2006年10月09日 00:00:00 作者:
復(fù)制代碼 代碼如下:
document.write('<DIV id="loadingg" style="HEIGHT:65px; WIDTH: 205px;POSITION: absolute; Z-INDEX:1000;border:3px #fff solid;text-align:center; font-size:12px; font-family:Arial, Helvetica, sans-serif;color:#660000;background:#222;opacity:.7;-moz-opacity:.7;filter: alpha(opacity=70); display:none;"><br/><font color="#FF6600"><strong>數(shù)據(jù)正在讀取中,請等候...</strong></font><br/><img src="images/loading.gif"/></DIV>')
function showloading()
{
var obj=document.getElementById("loadingg")
if (obj.style.display!="")
{
obj.style.left=((document.documentElement.clientWidth-parseFloat (obj.style.width))/2)+document.documentElement.scrollLeft+"px";
obj.style.top=((document.documentElement.clientHeight-parseFloat (obj.style.height))/2)+document.documentElement.scrollTop+"px";
obj.style.display="";
}else{obj.style.display="none";}
}
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 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) {//設(shè)置MiME類別
xmlhttp.overrideMimeType('text/xml');
}
}
return xmlhttp;
}
function getdata(url,obj1,obj2)
{ var xmlhttp=createxmlhttp();
if(!xmlhttp)
{alert("你的瀏覽器不支持XMLHTTP?。?);
return;
}
showloading()
xmlhttp.onreadystatechange=requestdata;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
function requestdata()
{ fopen(obj1);
//echo(obj1,"正在加載數(shù)據(jù),請稍等......");
//alert(xmlhttp.readyState)
if(xmlhttp.readyState==4)
{ if(xmlhttp.status==200)
{ if(obj1!=obj2){fclose(obj1);};
echo(obj2,xmlhttp.responseText);
showloading()
}
}
}
}
function postdata(url,obj,data)
{ var rnd=Math.random()
var xmlhttp=createxmlhttp();
if(!xmlhttp)
{
alert("你的瀏覽器不支持XMLHTTP!!");
return;
}
showloading()
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,"正在提交數(shù)據(jù),請稍等......");
if(xmlhttp.readyState==4)
{ if(xmlhttp.status==200)
{
echo(obj,xmlhttp.responseText);
reget(rnd);
setTimeout("echo('showresult','')",2000);
echo('Message','')
showloading()
}
}
}
}
function lTrim(str)
{
if (str.charAt(0) == " ")
{
//如果字串左邊第一個字符為空格
str = str.slice(1);//將空格從字串中去掉
//這一句也可改成 str = str.substring(1, str.length);
str = lTrim(str); //遞歸調(diào)用
}
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); //遞歸調(diào)用
}
return str;
}
//去掉字串兩邊的空格
function trim(str)
{
return lTrim(rTrim(str));
}
function f(obj)
{
return trim(eval("document.ajax_post."+obj+".value"));
//return trim($(obj).value);
}
function SaveReply()
{ if(f("username")=="")
{ alert("請?zhí)顚懹脩裘?);
return false;
}
if(f("Message")=="")
{ alert("內(nèi)容不可為空");
return false;
}
var validate,password,log_DisKey=0,log_DisURL=0,log_DisSM=0
validate=""
password=""
if(document.ajax_post.log_DisKey.checked){
log_DisKey=f("log_DisKey")
}
if(document.ajax_post.log_DisURL.checked){
log_DisURL=f("log_DisURL")
}
if(document.ajax_post.log_DisSM.checked){
log_DisSM=f("log_DisSM")
}
if((typeof eval(document.ajax_post.validate))!="undefined"){
if(f("validate")=="")
{ alert("請?zhí)顚戲炞C碼");
return false;
}else{
validate=f("validate");
}
}
if((typeof eval(document.ajax_post.password))!="undefined"){
password=f("password");
}
data="username="+escape(f("username"))+"&password="+escape(password)+"&validate="+escape(validate)+"&log_DisSM="+escape(log_DisSM)+"&log_DisURL="+escape(log_DisURL)+"&log_DisKey="+escape(log_DisKey)+"&Message="+escape(f("Message"))+"&logID="+escape(f("logID"))+"&action="+escape(f("action"));
//alert(data);
postdata("wbc_blogcomm.asp","showresult",data);
return true;
}
相關(guān)文章
ajax實現(xiàn)點擊不同的鏈接讓返回的內(nèi)容顯示在特定div里
過ajax實現(xiàn)在一個web頁面點擊不同的鏈接,然后將返回的結(jié)果顯示在該頁面固定的div里2014-06-06Ajax實現(xiàn)省市區(qū)三級級聯(lián)(數(shù)據(jù)來自mysql數(shù)據(jù)庫)
這篇文章主要為大家詳細(xì)介紹了Ajax實現(xiàn)省市區(qū)三級級聯(lián),數(shù)據(jù)來自mysql數(shù)據(jù)庫,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09Ajax方式實現(xiàn)定期更新頁面某塊內(nèi)容的方法
這篇文章主要介紹了Ajax方式實現(xiàn)定期更新頁面某塊內(nèi)容的方法,涉及jquery中l(wèi)oad方法Ajax調(diào)用及setInterval定時執(zhí)行的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07