473,226 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

Classic ASP and AJAX

I am creating an image gallery in classic asp using a access database. I display the thumbnails and story on the page. When a user clicks on the image, I popup the full image. Popup is necessary to help to combat people taking the images. I am trying to count the number of views or clicks each photo has, I am storing this in an Access database.

I can't or don't know how to have the onclick event fire both the javascript to popup the window and the vbscript to write to the database.

I believe AJAX or XMLHttpRequest is the proper way to do this, I truly do not want a complete page refresh and then the popup. The problem is, I have no clue as to how to do this.

Thank you in advance for your time,
Jun 5 '07 #1
1 5176
I think I have this figured out. However, I do have a problem. This will only increment each ID once, if you open this window in a new browser, you can increment the values again. I have only tested in IE6. There is a link to a demo at the bottom.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  3. <HTML>
  4. <HEAD>
  6. <style>
  7. body {
  8.  font-family: Verdana;
  9.  font-size: 9pt;
  10. }
  12. h3 {
  13. font-family: verdana;
  14. text-align: center;
  15. }
  17. a {
  18.   color: #FF0033;
  19. }
  21. a:hover {
  22.   color: #000;
  23. }
  24. </style>
  25. <script>
  26. function createRequestObject() {
  27.     var ro;
  28.     var browser = navigator.appName;
  29.     if(browser == "Microsoft Internet Explorer"){
  30.         ro = new ActiveXObject("Microsoft.XMLHTTP");
  31.     }else{
  32.         ro = new XMLHttpRequest();
  33.     }
  34.     return ro;
  35. }
  37. var http = createRequestObject();
  39. function sndReq(imageid) {
  40.     http.open('get', 'connect.asp?imageid='+imageid);
  41.     http.onreadystatechange = handleResponse;
  42.     http.send(null);
  43. }
  45. function handleResponse() {
  46.     if(http.readyState == 4){
  47.         var response = http.responseText;
  48.         var update = new Array();
  50.         if(response.indexOf('|' != -1)) {
  51.             update = response.split('|');
  52.             document.getElementById("image_id").innerHTML = "You clicked to increment Image ID : " + update[0];
  53.             document.getElementById("num").innerHTML = "Incremented Number of Clicks : " + update[1];
  54.         }
  55.     }
  56. }
  57. </script>
  58. </HEAD>
  60. <BODY>
  61. This is the original pull from the database.
  62. <br><br>
  63. <%
  65. set conn = server.createobject("adodb.connection")
  66. DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
  67. DSNtemp=dsntemp & "DBQ=" & server.mappath("cgi-bin/test.mdb")
  68. conn.Open DSNtemp
  69. sqlstmt = "SELECT * from Table1 Order by ImageID" 
  70. Set rs = Server.CreateObject("ADODB.Recordset")
  71. rs.Open sqlstmt, conn, 3, 3
  72. Do While Not rs.EOF    
  73. imgid = rs("ImageID")
  74. click = rs("num")
  75. response.write ("Image ID : " & imgid)
  76. response.write ("<br>")
  77. response.write ("Number of clicks : " & click)
  78. response.write ("<br><br>")
  79. rs.movenext
  80. loop
  81. rs.close
  82. set rs = nothing
  83. conn.close
  84. set conn = nothing
  85. %>
  86. <br>
  87. Click on one of the links to increment the count.
  88. <br><br>
  89. <a onClick="javascript:sndReq('1');" onmouseover="this.style.cursor='pointer'">Click to Increment 1</a>
  90. <br><br>
  91. <a onClick="javascript:sndReq('2');" onmouseover="this.style.cursor='pointer'">Click to Increment 2</a>
  92. <br><br><br>
  93. <div ID="image_id">The image ID you clicked will show here once you click the increment.</div>
  94. <br>
  95. <div ID="num">The new data will show here once you click the increment.</div>
  96. <br><br><br>
  97. There is something going on here that I can not figure out.
  98. <br>
  99. This will only increment each ID once, if you open this window in a new browser, you can increment the values again.
  100. </BODY>
  101. </HTML>
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Set theID = Request.QueryString("imageid")
  4. set conn = server.createobject("adodb.connection")
  5. DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
  6. DSNtemp=dsntemp & "DBQ=" & server.mappath("cgi-bin/test.mdb")
  7. conn.Open DSNtemp
  8. sqlstmt = "SELECT * from Table1 WHERE ImageID=" & theID
  9. Set rs = Server.CreateObject("ADODB.Recordset")
  10. rs.Open sqlstmt, conn, 3, 3
  11. num = rs("num")
  12. numC = num + 1
  13. rs.Fields("num") = numC
  14. rs.update
  15. response.write (theID & "|" & numC)
  16. rs.close
  17. set rs = nothing
  18. conn.close
  19. set conn = nothing
  21. %>
I am still trying to work out why you would have to reload the page to increment either count more than once.

A small demo

Thanks for taking a look at this,
Jun 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Yarco | last post by:
I want to use "Ajax" to create my web for hobby. But i don't know whether "Ajax" is mature... And what about with php? Someone have experience on it? ....
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
by: needin4mation | last post by:
I can't find out if Microsoft supports "Classic" asp or if they only support asp.net? I'm not really sure what support means in either context, really, except that they tell customers not to use...
by: MarkusJNZ | last post by:
Hi, I am trying to pass an number from a classic asp webpage to a .NET webservice. Because my C# webservice expects an integer and classic ASP uses variants I keep getting problems with object...
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
by: luigi.corrias | last post by:
Hello Everybody Some one can suggest me what is the best component used for good old Classic Asp? Thanks Luigi
by: Victor | last post by:
Can I get the events in GLOBAL.ASAX to fire if a classic ASP page is being accessed by the user?
by: prarthanaraut | last post by:
Hi, I am getting Browser problerm while using AJAX in classic ASP code. I want to execute some asp code when user clicks on checkboxes on one page without refreshing the page. I have...
by: andwan0 | last post by:
I have a legacy classic ASP website with lots of classic AJAX (many ASP files specially made for processing AJAX requests). We are slowly migrating the website to ASP.NET 2.0 and developing under...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.