Yarr The Pirate! http://www.yarrthepirate.com/phpbb3/ |
|
Question about AJAX (web based shit, not the cleaning crap) http://www.yarrthepirate.com/phpbb3/viewtopic.php?f=5&t=8642 |
Page 1 of 1 |
Author: | Kayne [ Thu Mar 09, 2006 5:42 pm ] |
Post subject: | Question about AJAX (web based shit, not the cleaning crap) |
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 |
Author: | Kayne [ Thu Mar 09, 2006 6:06 pm ] |
Post subject: | |
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 |
Author: | Kaylia [ Thu Mar 09, 2006 6:26 pm ] |
Post subject: | |
I wish I would have learned anything after 3 years in computer science. ![]() |
Author: | Hale [ Thu Mar 09, 2006 6:27 pm ] |
Post subject: | |
I had a cat named Ajax once. Then one day I came home and found it dead in the bathroom sink. |
Author: | Kayne [ Thu Mar 09, 2006 7:04 pm ] |
Post subject: | |
k i hate you guys =p |
Author: | Kaylia [ Thu Mar 09, 2006 7:09 pm ] |
Post subject: | |
Kayne wrote: k i hate you guys =p
It's okay, we share the same feeling ![]() |
Author: | Supafly [ Fri Mar 10, 2006 1:37 am ] |
Post subject: | |
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! |
Author: | Hobo [ Fri Mar 10, 2006 1:14 pm ] |
Post subject: | |
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. |
Author: | Hobo [ Fri Mar 10, 2006 1:28 pm ] |
Post subject: | |
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 <% } %> |
Author: | Kayne [ Fri Mar 10, 2006 4:24 pm ] |
Post subject: | |
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. |
Page 1 of 1 | All times are UTC - 5 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |