Forum Moderators: open
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 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.
Below is a link to the page I am trying to do this on, hopefully, this will give some insight as to what I am doing.
<url removed>
Thank you in advance for your time,
JR
[edited by: encyclo at 1:49 pm (utc) on June 4, 2007]
[edit reason] no URLs please, see terms of service [/edit]
I assume the only time the popup appears is when the user clicks on the image. If this is the case why not just have a counter for that image in the database that has 1 added to it wheneveer the popup is opened.
The popup is obviously aware of which pic is being opened and therefore adding 1 to a count for that image shouldn't be an issue, dependant upon how you db is structured.
No need for AJAX.
inside that page, put something like this
<!--#include file="includes/connect.asp"-->
<%
'open database funtion from connect.asp
OpenDatabase Dataconn
Set picRS = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT xImageLocation FROM pictures WHERE id = " & (request("id")*1)
picRS.Open SQL,DataConn' check to make sure picture is in database
If Not picRS.eof Then
oUrl = picRS(0)
oClics = (picRS(1) + 1)' update field containing the amount of views
SQLupd = "UPDATE pictures SET xClics = "&oClics&" WHERE id = " & (request("id")*1)
DataConn.Execute ( SQLupd )Else
response.write "Sorry, there has been a problem displaying this image."
End IfpicRS.Close
Set picRS = Nothing
CloseDatabase Dataconn'redirect to the picture
response.redirect(oUrl)
%>
Then call the page like so: picture.asp?id=12345
My thoughts were if I used AJAX, I could update the story page with the total number of clicks and popup the window with the photo in it. I do not want to open a new page nor do I want to refresh the page.
Thanks,
JR
I can not get the code to show up properly on the forum, I must be doing something wrong.
Basically, I used the get object to call on an ASP page that updates the database. I still can not figure out why you have to open the page in a new window to be able to increment the values again.
Some relevant javascript code
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}var http = createRequestObject();
function sndReq(imageid) {
http.open('get', 'connect.asp?imageid='+imageid);
http.onreadystatechange = handleResponse;
http.send(null);
}
Thanks,
JR
Does the ASP page return the new count..?
If so this can be used to update the original page.