473,394 Members | 1,893 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,394 software developers and data experts.

Help with AJAX: combine two pages into one

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_Dynamic.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 2444
acoder
16,027 Expert Mod 8TB
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
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...
3
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...
1
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...
5
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. ...
10
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...
1
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"...
2
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...
21
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...
29
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.