How to realize ajax message board
Editor to share with you how to achieve the ajax message board, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
The code is as follows:
/ / JavaScript Document
Function $(id)
{
Return document.getElementById (id)
}
Function echo (obj,html)
{
$(obj) [xss_clean] = html
}
Function fopen (obj)
{
$(obj) .style.display = ""
}
Function fclose (obj)
{
$(obj) .style.display = "none"
}
Function lTrim (str)
{
If (str.charAt (0) = = "")
{
/ / if the first character on the left of the string is a space
Str = str.slice (1); / / remove spaces from the string
/ / this sentence can also be changed to str = str.substring (1, str.length)
Str = lTrim (str); / / Recursive call
}
Return str
}
/ / remove the space to the right of the string
Function rTrim (str)
{
Var iLength
ILength = str.length
If (str.charAt (iLength-1) = "")
{
/ / if the first character to the right of the string is a space
Str = str.slice (0, iLength-1); / / remove spaces from the string
/ / this sentence can also be changed to str = str.substring (0, iLength-1)
Str = rTrim (str); / / Recursive call
}
Return str
}
/ / remove the spaces on both sides of the string
Function trim (str)
{
Return lTrim (rTrim (str))
}
Function sck (s)
{
Return s.replace (/\ nUnig, "[br]")
/ / s=s.replace (chr (13) & chr (23), "")
/ / return s
}
Function f (obj)
{
Return trim (eval ("document.forms [0]." + obj+ ".value"))
/ / return trim ($(obj) .value)
}
Function setf (obj)
{
Return eval ("document.forms [0]." + obj+ ".focus ();")
}
Function show (obj)
{
Var slots $(obj) .style
S. Displaygirls. Displaygirls = "none"? "": "none"
}
Function echo (obj,html)
{
$(obj) [xss_clean] = html
}
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 xMLHttpRequestrated undefined) {
Xmlhttp = new XMLHttpRequest ()
If (xmlhttp.overrideMimeType) {/ / set the MiME category
Xmlhttp.overrideMimeType ('text/xml')
}
}
Return xmlhttp
}
Function getnum (url,obj)
{
/ / var b = ""
Var xmlhttp=createxmlhttp ()
If (! xmlhttp)
{
Alert ("your browser does not support XMLHTTP clients!")
Return
}
Xmlhttp.onreadystatechange=requestdata
Xmlhttp.open ("GET", url,true)
Xmlhttp.send (null)
Function requestdata () {
If (xmlhttp.readyState==4)
{
If (xmlhttp.status==200)
{
(obj) .value=xmlhttp.responseText
}
}
}
}
Function getdata (url,obj1,obj2)
{
Var xmlhttp=createxmlhttp ()
If (! xmlhttp)
{
Alert ("your browser does not support XMLHTTP clients!")
Return
}
Xmlhttp.onreadystatechange=requestdata
Xmlhttp.open ("GET", url,true)
Xmlhttp.send (null)
Function requestdata ()
{
Fopen (obj1)
Echo (obj1, "loading data, please wait a moment.")
If (xmlhttp.readyState==4)
{
If (xmlhttp.status==200)
{
If (obj1 updated obj2) {fclose (obj1);}
Echo (obj2,xmlhttp.responseText)
}
}
}
}
Function postdata (url,obj,data)
{
Var xmlhttp=createxmlhttp ()
If (! xmlhttp)
{
Alert ("your browser does not support XMLHTTP clients!")
Return
}
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, "data is being submitted, please wait a moment.")
/ / alert (xmlhttp.readyState)
If (xmlhttp.readyState==4)
{
/ / alert (xmlhttp.status)
If (xmlhttp.status==200)
{
Echo (obj,xmlhttp.responseText)
}
}
}
}
Function checkform (obj,id)
{
If (f ("user") = "")
{
Alert ("Please leave your name!")
Setf ("user")
Return false
}
If (f ("user") .length > 10 & & f ("user") 50)
{
Alert ("Sorry the title is too long!")
Setf ("title")
Return false
}
If (f ("content") = "")
{
Alert ("messages cannot be empty!")
Setf ("content")
Return false
}
Data= "user=" + escape (f ("user")) + "& title=" + escape (f ("title")) + "& content=" + escape (document.forms [0] .content.value) + & reply= + escape (f ("reply"))
/ / alert (data)
/ / data= "content=" + escape (sck (f ("content")
If (obj== "add")
{
/ / alert (obj)
Postdata ("file.asp?action=addsave", "contentdata", data)
} else if (obj== "reply")
{
Postdata ("file.asp?action=replysave", "contentadmin" + id,data)
}
Return true
}
Function adminlogin ()
{
If ($(adminuser ") .value==")
{
Alert ("Management account cannot be empty!")
("adminuser") .focus ()
Return false
}
If ($(adminpwd ") .value==")
{
Alert ("Administrative password cannot be empty!")
("adminpwd") .focus ()
Return false
}
Data= "adminuser=" + escape ($("adminuser") .value) + "& adminpwd=" + escape ($("adminpwd") .value)
Postdata ("file.asp?action=checkadmin", "loginlist", data)
Return true
}
Function adreset ()
{
$("adminuser") .value= ""
$("adminpwd") .value= ""
}
Function linktool ()
{
If ($("linktool") [xss_clean] = "self-help link")
{
$("linktool") [xss_clean] = "friendly link"
Getdata ("list.asp?action=addlink", "linklist", "linklist")
} else
{
$("linktool") [xss_clean] = "self-help link"
Getdata ("list.asp?action=linklist", "linklist", "linklist")
}
}
Function addlink ()
{
If ($(home ") .value==")
{
Alert ("site name cannot be empty")
("home") .focus ()
Return false
}
If ($(url ") .value==")
{
Alert ("website address cannot be empty!")
("url") .focus ()
Return false
}
Data= "home=" + escape ($("home") .value) + "& url=" + escape ($("url") .value)
Postdata ("list.asp?action=linksave", "linklist", data)
Return true
}
Function linkreset ()
{
$("home") .value= ""
$("url") .value= ""
}
Function updatepwd ()
{
If (f ("user") = "")
{
Alert ("Please enter an administrative account!")
Setf ("user")
Return false
}
If (f ("npwd") = "")
{
Alert ("Please enter the administrative password!")
Setf ("npwd")
Return false
}
If (f ("npwd")! = f ("npwd1"))
{
Alert ("New password and confirmation password are not the same!")
Setf ("npwd")
Return false
}
Data= "user=" + escape (f ("user")) + "& pwd=" + escape (f ("npwd"))
Postdata ("list.asp?action=savepwd", "contentdata", data)
Return true
}
Function updateinfo ()
{
If (f ("gonggao") = "")
{
Alert ("announcement content cannot be empty!")
Setf ("gonggao")
Return false
}
If (f ("foot") = "")
{
Alert ("copyright information cannot be empty!")
Setf ("foot")
Return false
}
Data= "news=" + escape (document.forms [0] .gonggao.value) + "& foot=" + escape (document.forms [0] .foot.value)
Postdata ("list.asp?action=infosave", "contentdata", data)
Return true
}
The above is all the contents of the article "how to achieve the ajax message board". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!