 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 15th, 2010, 09:06 AM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
triggering a db function using jquery/get
Hi Imar,
I'm back!
I've done some reading on the jquery function and I've managed to set up the reveal using this:
this is my stripped down html page
<html>
<head>
<title></title>
</head>
<script>
$(document).ready(function(){
$(".contactseller").hide();
$("span.trigger").click(function(){
$(this).toggleClass("active").next().slideToggle(" slow");
return false; //Prevent the browser jump to the link anchor
});
});
</script>
<body>
</body>
'then below in my loop:
<span class="trigger">
<script>
$(document).ready(function(){
$.get("customer_update.asp?", { id: "<%=intproductid%>" } );
});
</script><a href="#"><span id="snone">Reveal Text;</span></a></span>
<div class="contactseller">
<p id="snone"> [email protected]</p>
<!--Content-->
</div>
</html>
However, this doesn't seem to be triggering my db update in customer_update.asp
I realise I'm digressing a bit into jquery so not sure if this is the correct forum but I'm just going to follow the thread for the mo!
thanks
Adam
|
|

December 15th, 2010, 12:32 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Not sure if I understand the problem / question. There's some stuff that confuses me....
Code:
$(document).ready(function(){
$.get("customer_update.asp?", { id: "<%=intproductid%>" } );
});
Document ready fires as soon as the DOM is finished loading. Are you sure you want to call this immediately on the first hit to the page and not afer some user interaction?
Loop? What loop?
Does <%=intproductid%> have a valid value (check the HTML source in the browser).
Fially, I am not sure when / where / how you want to trigger the GET request for the database update.
Cheers,
Imar
|
|

December 15th, 2010, 12:59 PM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
triggering a db function using jquery/get
Hi Imar
No, I want it to fire when the user clicks:
<a href="#"><span id="snone">Reveal Text;</span></a>
the loop I mention is the one that loops through the recordset on the page and pulls out the var intproductid for each entry.
thanks in advance
Adam
|
|

December 15th, 2010, 01:09 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
In that case, you could bring it down to something like this:
Code:
<body>
<form>
<div>
<a href="#" onclick="Update(1)">Do 1</a>
<a href="#" onclick="Update(2)">Do 2</a>
</div>
</form>
<script type="text/javascript">
function Update(id) {
$.get("Test.asp?", { id: id });
}
</script>
</body>
Each link calls Update and passes the ID. The Update method then calls the ASP page and forwards the ID in the query string. You can replace Update(1) with your ASP ID, like this:
Code:
<a href="#" onclick="Update(<%=intproductid%> )">Do <%=intproductid%> </a>
Hope this helps,
Imar
|
|

December 15th, 2010, 06:36 PM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
triggering a db function using jquery/get
thanks Imar, I think I must be nearly there with your help.
This is what I have:
<form>
<script type="text/javascript">
function Update(id) {
$.get("update.asp?", { id: id });
}
</script>
<a href="#" onclick="Update(<%=intproductid%>)"><span id="snone">Contact </span></a></span>
<div class="contactseller">
<p id="snone">reveal text</p>
<!--Content-->
</div>
</form>
it's all fine as in no errors but it's not triggering the update.asp page - am I missing something? I guess I must be.
thanks
Adam
|
|

December 15th, 2010, 06:40 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Did you check the source as I suggested earlier to see if a) intproductid resulted in a value and b) it's a number and not a string?
Also, maybe the ASP page is called but has a problem of its own?
Imar
|
|

December 16th, 2010, 11:03 AM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
triggering a db function using jquery/get
Thanks Imar, I think we're getting there - thanks for hanging in there!
I added standard update query in the update.asp file and it worked!
i.e update tbl set value = 10 - it inserted the value
However it's not working with my variable I'm passing it seems - this is my source code to trigger the update file, update.asp
<form>
<script type="text/javascript">
function Update(id) {
$.get("update.asp?", { id: id });
}
</script>
<a href="#" onclick="Update(3)">contact</a></span>
<div class="contact">
<p id="snone">reveal text here</p>
<!--Content-->
</div>
</form>
I'm wanting to pass the var '3' which I guess it's doing.
Also, is this value being passed by the querystring as that's how I'm trying to retrieve it on the update.asp page?
thanks
Adam
|
|

December 16th, 2010, 12:20 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
Also, is this value being passed by the querystring as that's how I'm trying to retrieve it on the update.asp page?
|
Yes; that's what the Get request method does with the info you pass to it in the second parameter.
However, I think I invented a question mark that shouldn't be there. Can you try this instead:
Code:
function Update(id) {
$.get("update.asp", { id: id });
}
without the question mark following the page name.
Also, make sure you call the right page. Earlier you said the update page was called customer_update.asp, not update.asp.
If that doesn't help, can you post the code for the ASP page?
Cheers,
Imar
|
|

December 16th, 2010, 12:49 PM
|
|
Authorized User
|
|
Join Date: Dec 2009
Posts: 85
Thanks: 16
Thanked 0 Times in 0 Posts
|
|
triggering a db function using jquery/get
Hi Imar
I took the ? out but no luck.
Here's the code for the customer_update.asp page. (sorry I altered the name of the file in the last post but only in the post, not the code)
<%
strSQL = "SELECT c.email, p.productname, p.visits FROM tblcustomer c, tbl_product p WHERE c.customerid " & _
" = p.customerid AND p.productid = '" & replace(request.QueryString("id"), "'", "''" ) & "'"
set rsEmail = con.execute(strSQL)
if rsEmail.eof then
rsEmail.movefirst
strEmail = rsEmail("email")
strProductname = rsEmail("productname")
intVisit = rsEmail("visits")
intVisitAdd = intVisit + 1
strSQL = "UPDATE tbl_product SET visits = " & intVisitAdd & " WHERE productid = '" & replace(request.QueryString("id"), "'", "''" ) & "'"
con.execute (strSQL)
strSubject = Application("Visit")
strEmailTo = Application("Mail_To")
strRecipientEmail = strEmail
strEmailMsg = "<html>" & _
"<head>" & _
"<title>" & Application("Visit") & "</title>" & _
"<style>" & _
"body td { " & _
" font-family: Arial;" & _
" font-size: 12px;" & _
"}" & _
"</style>" & _
"</head>" & _
"<body>" & _
"<table border=""0"" cellspacing=""0"" cellpadding=""2"">" & _
" <tr>" & _
" <td colpsan=""2""> </td>" & _
" <td><b>" & server.HTMLEncode(strProductname) & "</b> from " & Application("Client_Name") & "</td>" & _
" <td></td>" & _
" </tr>" & _
" <tr>" & _
" <td><b>A copy of this email has been sent to:</b></td>" & _
" <td>" & Application("Mail_From") & "</td>" & _
" </tr>" & _
"</table>" & _
"<p> </p>" & _
"</body>" & _
"</html>"
con.close
set con = Nothing
boolEmailSent = SendEmail(strEmailTo, strSubject, strEmailMsg, True)
end if ' end rsEmail
thanks
Adam
|
|

December 16th, 2010, 04:52 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Adam,
Not sure what the problem is. In ASPX page I have this:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="#" onclick="Update(1)">Do 1</a> <a href="#" onclick="Update(2)">Do 2</a>
</div>
</form>
<script type="text/javascript">
function Update(id) {
$.get("Test.aspx", { id: id });
}
</script>
</body>
</html>
My Test.aspx code behind then looks like this:
Code:
Partial Class Test
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Dim id = Request.QueryString("Id")
End Sub
End Class
When I debug the application and click Do1, I get a request for Test.aspx and can access the ID from the querystring.
I know you're dealing with classic ASP but the concepts should be the same.
Things to look into:
1. Make sure your Do function gets called correctly (put debugger before the line with the get call to debug it) and make sure the jQuery library is referenced and linked correctly.
2. Make sure your ASP page is called correctly. Maybe you can debug it, or write to some log.
Cheers,
Imar
|
|
 |