473,597 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with AJAX: combine two pages into one

1 New Member
Hi,

I am still not able to get this working in a simple page. Please help me. I am badly stuck....

I am trying to view the contents of the Beverage Category. I have built it like a hierarchy in the form of styled <UL> tags.

Please assist me in combining the 2 pages into one page. I would extremely grateful.

My code is:

Categories_Dyna mic.asp
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!--#INCLUDE Virtual="/Scripts/Padmaja/Testing2/DB_Northwind.asp"-->
  4. <head>
  5. <style type="text/css">
  6. * {
  7.    border: 0;
  8.    padding: 0;
  9.    margin: 0;
  10. }
  11.  
  12. #menu {
  13.   padding:0;
  14.   margin:0;
  15.   }
  16. #menu li {
  17.   list-style-type:none;
  18.   }
  19.  
  20. #menu ul {
  21. padding: 0;
  22. margin: 6px;
  23. list-style-type: none;
  24. }
  25.  
  26. a.a_style:link {color:#0000ff; text-decoration:none;}
  27. a.a_style:visited {color:#0000ff; text-decoration:none;}
  28. a.a_style:hover {color:#ff0000; text-decoration:underline;}
  29. a.a_style:hover {color:#ff0000; text-decoration:underline;}
  30.  
  31. </style>
  32.  
  33. <script type="text/javascript">
  34.  
  35. var xmlHttp
  36.  
  37. function showProducts(str)
  38. {
  39. xmlHttp=GetXmlHttpObject()
  40. if (xmlHttp==null)
  41. {
  42. alert ("Browser does not support HTTP Request")
  43. return
  44. }
  45.  
  46. var url="getProducts.asp"
  47. url=url+"?ID="+str
  48. //alert(url);
  49. //url=url+"&sid="+Math.random()
  50. xmlHttp.onreadystatechange=stateChanged1
  51. xmlHttp.open("GET",url,true)
  52. xmlHttp.send(null)
  53. }
  54.  
  55. function stateChanged1()
  56. {
  57.     if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  58.     {
  59.         //objID = 'UI_'+el;
  60.         //document.getElementById(objID).innerHTML=xmlHttp.responseText
  61.         document.getElementById("content_products").innerHTML=xmlHttp.responseText
  62.     }
  63. }
  64.  
  65. function GetXmlHttpObject()
  66. {
  67. var objXMLHttp=null
  68. if (window.XMLHttpRequest) //Safari, Mozilla browers
  69. {
  70.     objXMLHttp=new XMLHttpRequest()
  71. }
  72. else if (window.ActiveXObject) //IE browsers
  73. {
  74.     objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  75. }
  76. return objXMLHttp
  77. }
  78.  
  79. function s_Hide(el){
  80.     //alert("Showing Element: "+el);
  81.     objID = 'UI_'+el;
  82.     //alert(objID);
  83.     obj = document.getElementById(objID).style;
  84.     (obj.display == 'none')? obj.display = 'block' : obj.display = 'none';
  85. }
  86.  
  87. </script>
  88.  
  89. <title>On Demand Building of tree with User OnClick</title>
  90. </head>
  91.  
  92. <body>
  93.  
  94. <form name="Customers" id="Customers" action="">
  95.  
  96. <%
  97.  
  98. Dim rs
  99. Set rs = Server.CreateObject("ADODB.Recordset")
  100. sSQL = "SELECT CategoryID, CategoryName FROM Categories WHERE CategoryID = 2"
  101.  
  102. rs.open sSQL, Conn
  103.  
  104. Dim aCategory
  105.  
  106. If not rs.EOF Then
  107.     'Dump the recordset into the above array
  108.     aCategory = rs.getRows()
  109.  
  110.     rs.Close
  111.     Set rs = Nothing
  112.  
  113.     Dim iRows
  114.  
  115.     For iRows = 0 to UBound(aCategory, 2)
  116.     CatID = aCategory(0, iRows)
  117.     %>
  118.     <ul id="menu">
  119.         <li>
  120.             <input type="radio" checked name="prodid" id="Catid<%=aCategory(0, iRows)%>" value="<%=aCategory(0, iRows)%>">
  121.             <a href="#" class="a_style" onclick="showProducts(<%=aCategory(0, iRows)%>);s_Hide('<%=aCategory(0, iRows)%>'); return false;"><%=aCategory(1, iRows)%></a>
  122.             <ul id="UI_<%=aCategory(0, iRows)%>">
  123.             <%
  124.             'QS = Request.Querystring("ID")
  125.             'Now pass the querystring to the following function.
  126.             'if QS = trim(aCategory(0, iRows)) then
  127.                 'Call GetProducts (CatID, Counter)
  128.             'end if
  129.             %>
  130.             <div id="content_products">
  131.             </div>
  132.             </ul>
  133.         </li>
  134.     </ul>
  135.     <%
  136.     Next 'iRows
  137. End If
  138. %>
  139. </form>
  140. </body>
  141. </html>
  142. <%
  143. Conn.Close
  144. Set Conn = Nothing
  145. %>
  146.  
getProducts.asp

Expand|Select|Wrap|Line Numbers
  1. <%
  2. ProdID = Request.Querystring("ID")
  3. 'Response.Write ProdID
  4. Call GetProducts (ProdID, Counter)
  5.  
  6.  
  7. startTime = Now()
  8.  
  9. 'get the Products using a function
  10.  
  11. Function GetProducts(ProdID, Counter)
  12.  
  13.         sql = "SELECT CategoryID, ProductName, ProductID FROM Products " & _
  14.               "where CategoryID = " & ProdID & " " & _
  15.               "order by ProductName "
  16.  
  17.         'Response.Write sql
  18.         'Response.End
  19.  
  20.         Dim rs2
  21.         set rs2 = Server.CreateObject("ADODB.Recordset")
  22.         rs2.open sql, Conn
  23.  
  24.         Dim aProducts
  25.  
  26.         If not rs2.EOF then
  27.  
  28.             aProducts = rs2.GetRows()
  29.  
  30.             'Close Recordset to use the new array with the 2 columns data
  31.             rs2.Close()
  32.             set rs2 = Nothing
  33.  
  34.             'Declare Constants for the above SQL columns for better readability
  35.             'Use these Constants instead of referring to the array numeric indexes
  36.             Const c_CatID = 0
  37.             Const c_ProductName = 1
  38.             Const c_ProductID = 2
  39.  
  40.             'Ubound(MyArray,1) 'Returns the Number of Columns
  41.             'Ubound(MyArray,2) 'Returns the Number of Rows
  42.  
  43.             Dim iRowLoop
  44.  
  45.             For iRowLoop = 0 to UBound(aProducts, 2)
  46.             %>
  47.             <li>
  48.                     <input type="radio" name="prodid" id="prodid<%=aProducts(c_ProductID,iRowLoop)%>" value="<%=aProducts(c_ProductID,iRowLoop)%>">
  49.                     <%=aProducts(c_ProductName,iRowLoop)%>
  50.                     <%
  51.                     Counter = Counter + 1
  52.                     Counter = Counter - 1
  53.                     %>
  54.             </li>
  55.             <%
  56.             Next 'iRowLoop
  57.         End If 'rs2.EOF
  58.  
  59. End Function
  60. %>
  61.  
  62.  
Thanks. Any input how to combine the two pages into one page?
Dec 27 '06 #1
1 2475
acoder
16,027 Recognized Expert Moderator MVP
You could combine both pages into one, but it'd just make maintenance more difficult. You'd have to have separate code within one page - one for the normal page and the other for Ajax-called code. It's much easier to maintain separated.
Jun 3 '08 #2

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

Similar topics

4
2139
by: yabba | last post by:
w2k server... after rebooting the event viewer/application log shows multiple restarts of Active Server Pages and they continue to build in memory as each start produces a IWAM_SERVERNAME in the task manager. there might be 10 - 20 starts without a stop... when I restart iis services it takes a long time as each started service is stopped and the associated IWAM_SERVERNAME is closed. this seems to be something new and when checking...
3
1476
by: Adrian | last post by:
Hi All, I am a big fan of the Codebehind model. I would like to continue to keep my .ASPX pages FREE of any 'LOGIC' and keep it PURE 'HTML'. I would like to know how many of you handle the following situation. (In pseudo code to illustrate my point) <html> <body> if (condition)
1
1380
by: robert.differentone | last post by:
It is possible to fetch html/php pages using AJAX. How can I load the fetched page? i.e. I want to use AJAX to prefetech pages ( imitate cache). Does anybody knows how to do it? Any help is appreciated ! Thanks, R.
5
1309
by: Kristen | last post by:
I am using ASP.Net 2.0 and I need to create a web page on the fly based on what information is in the database. The page is going to have certain controls like text boxes and labels and buttons. I was wondering what the best method is to carry this out. I was thinking about using a class to generate the HTML on the fly or maybe a stored procedure. Can anyone point me in the right direction? Thanks
10
4399
by: celoftis | last post by:
Using VS 2005: This morning, following the instructions here: http://ajax.asp.net/docs/overview/InstallingASPNETAJAX.aspx, I installed ASP.NET AJAX on my WinXP Pro development machine. Following that, I installed the "November 2006 CTP" and "Control Toolkit" - then I re-booted my machine. Next I tried to create a simple, sample page... I have the AJAX controls in my toolbox, but when I drag on onto my page it gets underlined - denoting...
1
7548
by: =?Utf-8?B?TGFycnkgRXBu?= | last post by:
I have an app using Ajax. The scriptmanager is within the form that is within the master page. I also have web user controls that are doing partial rendering and are "borrowing" or "inheriting" the scriptmanager from the master page. Heck, when they're rendered, the scriptmanager is on all the pages and it works. However, in the VS2005 designer, I constantly see "Can't render image" errors, and it's nearly impossible to effectively use...
2
1301
by: Arthur Dent | last post by:
Hello all, I have a site which was a .NET 2.0 AJAX 1.0 site. I opened it up in VWDExpress 2008, and changed it to a 3.5 site, then subsequently changed it back to a 2.0 site. Now, my references to AJAX no longer work. The web server has both the new (3.5), And old versions (1.0.61025.0) installed. If I look at the references in my project properties, it shows System.Web.Extensions, 1.0.61025.0 as an included reference, from the GAC.
21
5614
by: wizdom | last post by:
I've tried a few things but nothing seems to work, i'm starting to think this isnt possible. I basically am looking to have the user click on the video number, then have the video load in its own section on the page. I'm currently using iframes as a work around and have been trying to read up on Ajax as another way around it. Problem is, i think using iframes i'm losing important keywords that would usually be right on the page. i initially...
29
24377
by: FreshRob | last post by:
I have been trying to fix this issue the whole of today and have gotten no where. I am developing a new website, and wanted it to display a webpage in lightbox and have an external page added to the main page, both worked successfully apart, but it wasn't until I combined them that I have had an issue. My aim was to have ajax add the external page into a div and then load lightbox from that div, though that is where the problem lies as I can...
0
7969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7886
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1494
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.