It is currently Thu May 08, 2025 5:24 pm View unanswered posts | View active topics |


Board index » Community » Community Discussion


Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Question about AJAX (web based shit, not the cleaning crap)
PostPosted: Thu Mar 09, 2006 5:42 pm 
Spammer, to the max!
User avatar

Joined: Mon May 17, 2004 1:29 pm
Posts: 1887
Doesn't AJAX tax the web server/database server more than not using it? Everything I've read says it does the opposite, but I just don't see how refreshing information everytime you hit a key is less taxing on a server than entering in information and hitting a submit button.

Example:

Checking a database against a username that is being entered. If found, it will tell you so before you hit submit. While this can be done by populating an array of names upon requesting the page to choose a username, it has the flaw of missing new usernames that were registered while you were still on the form.

Now, the thing is... everytime the onkeyup event occurs you're going to be linking to the function that processes an asp page (or php... whatever basically the same thing) that will be connecting to a database to grab the newest information and check the user input against it.

How is this not more taxing on the server than just letting the user submit the form and check against the values then, re-populating the fields that are correct and erasing the ones that are not along with displaying some red text next to them saying what's wrong?

Or am I going about this all wrong? Maybe AJAX is only supposed to be for preventing a refresh of a page to show queues after a search is conducted, rather than submitting a form to do so?

Thanks irl =p


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 6:06 pm 
Spammer, to the max!
User avatar

Joined: Mon May 17, 2004 1:29 pm
Posts: 1887
btw heres some sample code i didnt test but just whipped up in hopes of explaining what im talking about:

main page (lets call it default.htm for the hell of it):
Code:
<html>
<head>
<title>yarr's penis</title>
<script type="text/javascript">
<!--
function showLength(str)
{
  if(str.length)
  {
    xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHTTP.onreadystatechange = stateChanged;
    xmlHTTP.open("GET","findlength.asp?length=" + str);
    xmlHTTP.send(null);
  }
  else
  {
    document.getElementById("yarrspenislength").innerHTML = "";
  }
}
function stateChanged()
{
  if(xmlHTTP.readyState==4 || xmlHTTP.readyState=="complete") document.getElementById("yarrspenislength").innerHTML = xmlHTTP.responseText;
}
//-->
</script>
</head>
<body>
<input type="text" onkeyup="showLength(this.value);"/>
<div id="yarrspenislength"></div>
</body>
</html>


findlength.asp page
Code:
<%@ language="javascript" %>
<%
length = Request.QueryString("length");
penislength = new Array("6.5","7","7.5");
for(i=0;i<penislength.length;i++)
{
  if(length==penislength[i])
  {
    %>
omg yarr's penis is <%=length%> inches irl
    <%
  }
}
%>


btw I'm not gay just bored and couldn't think of any other sample code to write

oh and I dunno why yarr's penis is 6.5, 7, and 7.5 inches either


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 6:26 pm 
Posts way too much
Posts way too much
User avatar

Joined: Thu Oct 28, 2004 10:31 am
Posts: 3267
I wish I would have learned anything after 3 years in computer science. :neutral: Can't help you much here

_________________
Image
Image
Image
Main: War75/Sam63/Blm71/Rng45
Sub: Nin37/Thf37/Whm37/Mnk30
Three nation: Done Zilart: Done CoP: Done


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 6:27 pm 
Decent Challenge
Decent Challenge

Joined: Fri Mar 25, 2005 8:54 pm
Posts: 465
I had a cat named Ajax once. Then one day I came home and found it dead in the bathroom sink.

_________________
-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 7:04 pm 
Spammer, to the max!
User avatar

Joined: Mon May 17, 2004 1:29 pm
Posts: 1887
k i hate you guys =p


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 7:09 pm 
Posts way too much
Posts way too much
User avatar

Joined: Thu Oct 28, 2004 10:31 am
Posts: 3267
Kayne wrote:
k i hate you guys =p



It's okay, we share the same feeling :)

_________________
Image
Image
Image
Main: War75/Sam63/Blm71/Rng45
Sub: Nin37/Thf37/Whm37/Mnk30
Three nation: Done Zilart: Done CoP: Done


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 1:37 am 
Spammer, to the max!
User avatar

Joined: Sat Dec 11, 2004 4:24 am
Posts: 1593
Location: Reflecting...
I don't see much in all that code Kayne, I just see blond here, brunette there etc etc.

wake up monk, the matrix has u!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 1:14 pm 
Easy Prey
Easy Prey
User avatar

Joined: Thu Jul 01, 2004 1:01 pm
Posts: 211
Location: Seattle
Theoretically, AJAX should be less taxing to the server due to the XML response only including the needed data, and all the processing to generate the HTML is done client-side with javascript.

This can all change depending on how the process is architected. It the XML response is just as much work as generating a whole new page, then you have gained nothing.

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 1:28 pm 
Easy Prey
Easy Prey
User avatar

Joined: Thu Jul 01, 2004 1:01 pm
Posts: 211
Location: Seattle
Ideally, you want the server to return the smallest amount (lol, given the example) of information possible.

So something like this. (btw, I never use ASP so I guessed on syntax.)

Code:
<html>
<head>
<title>yarr's penis</title>
<script type="text/javascript">
<!--
function showLength(str)
{
  if(str.length)
  {
    xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHTTP.onreadystatechange = stateChanged;
    xmlHTTP.open("GET","findlength.asp?length=" + str);
    xmlHTTP.send(null);
  }
  else
  {
    document.getElementById("yarrspenislength").innerHTML = "";
  }
}
function stateChanged()
{
  if(xmlHTTP.readyState==4 || xmlHTTP.readyState=="complete") document.getElementById("yarrspenislength").innerHTML = 'omg yarr\'s penis is ' + xmlHTTP.responseText + ' inches irl';
}
//-->
</script>
</head>
<body>
<input type="text" onkeyup="showLength(this.value);"/>
<div id="yarrspenislength"></div>
</body>
</html>


findlength.asp page
Code:
<%@ language="javascript" %>
<%
length = Request.QueryString("length");
penislength = new Array("6.5","7","7.5");

if( in_array(length,penislength) )
{
   =length
}
else
{
  %> 0.5 <%
}

%>

_________________
Image


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 4:24 pm 
Spammer, to the max!
User avatar

Joined: Mon May 17, 2004 1:29 pm
Posts: 1887
thanks hobo =p

I'll find out soon enough if this is gonna fuck the servers over at work since I went ahead and just did it anyway.

Since I track who connects to the site when they begin their session I noticed that some dude in our electronic services division was looking at the page afterwards, so I'm wondering if I'm going to get told about this later :P He was probably checking logs wondering why there were so many GET requests happening in such a short period of time by the same user.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

Board index » Community » Community Discussion


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group