Sunday, November 8, 2009

Honey Rose Cigarettes Shop

Check TinyUrl and available user with ASP and AJAX Changing our state

When we create a new account at a site is very annoying that we have to fill out a long form, with unnecessary fields and learn on top of that we put the user already exists, this will give us an error that the best site we came back with the other data that you requested just enter different user, many of these sometimes having to enter the password again.

This can be solved very easily with AJAX, by sending a request to the user database to check whether or not we enter

The magic of AJAX makes code again, here the code:

ajax.asp PAGE:
\u0026lt;! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.0 Transitional / / EN">
\u0026lt;HTML>
\u0026lt;HEAD>
\u0026lt;TITLE> , ASP and AJAX username check Availability \u0026lt;/ TITLE>
\u0026lt;script language=”javascript”>
function OnChangedUsername()
{
if(document.form1.newuserid.value == “”)
{
document.form1.btnCheckAvailability.disabled = true;
}
else
{
document.form1.btnCheckAvailability.disabled = false;
}
}
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == “Microsoft Internet Explorer”){
ro = new ActiveXObject(”Microsoft.XMLHTTP”);
}else{
ro = new XMLHttpRequest();
}
return ro;
}

was http = CreateObject request object ();
sndReq function () {
http.open ('GET', 'ajax_username.asp? Username =' + document.form1.newuserid.value);
http.onreadystatechange = handle Response;
http.send (null);}

function handleEvent Response () {
if (http.readyState == 4) {response =
was http.responseText;
was update = new Array ();

if (response.indexOf (' = update[0];
}
}
}
</script>
</HEAD>
<BODY>

<form method=”post” action=”javascript:void(0);” name=”form1″>
<table> <tr>
<td><input type=”newuserid” name=”newuserid” id=”newuserid” size=”20″ onKeyUp=”OnChangedUsername();” />

</td>
</tr> <tr>
<td><input id=”btnCheckAvailability” type=”button”disabled=”disabled” value=”Check Availability”onClick=”sndReq();”></td>
</tr>
<tr>
<td><div ID=”username_chk”></div></td>
</tr>
<tr>
<td>Brought to you by <a href = "http://strangework.com" target = "_blank"> Brad Williams \u0026lt;/ a> \u0026lt;/ td>
\u0026lt;/ tr>
\u0026lt;/ table>
\u0026lt;/ form>

\u0026lt;/ BODY>
\u0026lt;/ HTML>



ajax_username.asp PAGE: \u0026lt;%
September username = Request.QueryString ("username")
'*** TU INICIO CONEXION DNS-LESS
db_username = "username" 'DB username DB_PASSWORD = "Password" 'DB password
db_catalog = "database_name"' DB name
dp_datasource = "192.168.1.1" 'IP DB
' *** END YOUR DNS-LESS CONNECTION

'CAN CHANGE THE ABOVE FOR YOUR OWN LINE CONNECTION

September
conn = Server.CreateObject ("ADODB.Connection")
conn.CommandTimeout = 0 c = "Provider = SQLOLEDB.1; User ID =" & db_username & "password =" & ; DB_PASSWORD & "Initial Catalog =" & db_catalog & "Data Source =" & dp_datasource & "Use Procedure forPrepare = 1; Auto Translate = True; Packet Size = 4096" conn.Open c


'*** ADJUST TO SELECT THIS CHECK WITH YOUR REAL NAME
TABLE SQL = " SELECT username FROM table WHERE username = '"& username &"' "September chk_username = Server.CreateObject (" ADODB.Recordset ")
chk_username.Open SQL, conn, 3, 3
chk_username.EOF = False Then If
response.write "User Not Available" Else

response.write "USER AVAILABLE" End if


chk_username.close
September chk_username
= nothing conn.Close Set Conn = nothing
%>




0 comments:

Post a Comment