Recommended: ASP restricted IP voting complete example code Due to work relationships, one of the functions is to vote on users, requiring the same IP to vote on the same user only once, post Asp code: % 'Author: Wurong Source: db_conn(dbs) Voteusername=trim(request.QueryString(username)) rs_create(select username from [user] where username ='
Due to work relationships, one of the functions is to increase the other party as a friend. As shown in the picture:
The method used is ajax, which requires less appropriate code:
<a href=javascript: void(0); onClick =add_username('<%= rs(username) %> ');>Add as a friend</a>, the js verification used:
<script language = JavaScript src=ajax.js></script>
<script>
//add user
function add_username(usr){
//
var sta;
var username=usr;
if(username!=){
if(username!=){
username=username=+username;
sta=postthttp(username,Add_Friend.asp);
if(sta==false){
alert (addition failed, server error);
}else{
if(parseInt(sta)==1)
alert (Congratulations, friends were added successfully!);
else
alert(sta);
}
}else{
alert (please enter your friend name);
}
}
}
</script>
ajax.js code:
http_request = false;
if (window.XMLHttpRequest) {
//For browsers such as Mozilla, Netscape, Safari, etc., create XMLHttpRequest
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
//If the header responding to by the server is not text/xml, you can call other methods to modify the header
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
// For Internet Explorer browser, create XMLHttpRequest
try {
http_request = new ActiveXObject(Msxml2.XMLHTTP);
} catch (e) {
try {
http_request = new ActiveXObject(Microsoft.XMLHTTP);
} catch (e) {}
}
}
return http_request;
}
//Get the responseText of Url
function getResponseText(url)
{
http_request=getRequest();
http_request.open('GET', url, false);
http_request.send(null);
if (http_request.readyState == 4)
{
// Received a complete server response
if (http_request.status == 200) {
//The HTTP server response value is OK
requestdoc = http_request.responseText;
//Write the string returned by the server to the area in the page with the ID message
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
}
//POST Submit data
function postthttp(str,url){
http_request=getRequest();
http_request.open('POST',url,false);
http_request.setRequestHeader(Content-Length,str.length);
http_request.setRequestHeader(CONTENT-TYPE,application/x-www-form-urlencoded);
http_request.send(str);
if (http_request.readyState == 4)
{
// Received a complete server response
if (http_request.status == 200) {
//The HTTP server response value is OK
requestdoc = http_request.responseText;
//Write the string returned by the server to the area in the page with the ID message
return requestdoc;
}else{
//requestdoc = http_request.status;
return false;
}
}
}
//Get the responseXML of Url
function getXMLResponseText(url)
{
http_request=getRequest();
http_request.open('GET', url, false);
http_request.send(null);
if (http_request.readyState == 4)
{
// Received a complete server response
if (http_request.status == 200) {
//The HTTP server response value is OK
requestdoc = http_request.responseXML;
//Write the string returned by the server to the area in the page with the ID message
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
}
Then process it in Add_Friend.asp.
<%
Response.ContentType=text/html; charset=gb2312
'The process program will not be posted. First, determine whether the user is logged in, whether the friend's username has been passed, whether the friend's username is legal, whether the friend's username is added for the first time, etc. If the increase is correct, return 1
If Add_Friend = 1 Then 'If you can add friends correctly, Add_Friend=1
response.write 1 'This value is automatically returned to js
Else
There was an error in response.write 'Please check the code
End If
%>
Return prompt as shown in the figure:
Share: ASP long numbers are separated by commas to display instance code % Function Comma(str) If Not(IsNumeric(str)) Or str = 0 Then Result = 0 ElseIf Len(Fix(str)) 4 Then Result = str Else Pos = Instr(1,str,.) If Pos 0 Then Dec = Mid(str,Pos) End if Res = StrReverse(Fix(str)) LoopCount = 1 While LoopCount =