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

Javascript code to retrieve result search results from database

7
Hye all..I'm Newbie..

I'm using asp.net..This code below I put in .aspx file..And become like that..
I want to make something like "WHEN USER PUT SOMETHING IN TEXTBOX AND CLICK THE BUTTON SEARCH..THE RESULT COMEOUT IN NEW ' div '..

I want to apply to my website..Using AJAX code..
I just copy the code from http://www.w3schools.com/ajax/ajax_database.asp.

Help me please..

HEAD

Expand|Select|Wrap|Line Numbers
  1. <%
  2.         Dim sql, conn, rs, x
  3.  
  4.         Response.Expires = -1
  5.         sql = "SELECT * FROM the_TABLE WHERE the_COLUMN="
  6.         sql = sql & "'" & Request.QueryString("q") & "'"
  7.  
  8.  
  9.         conn = Server.CreateObject("ADODB.Connection")
  10.         conn.Provider = "Microsoft.Jet.OLEDB.4.0"
  11.         conn.Open(Server.MapPath("../AJAXPage/db/Database1.mdb"))
  12.         rs = Server.CreateObject("ADODB.recordset")
  13.         rs.Open(sql, conn)
  14.         Response.Write("<table>")
  15.         Do Until rs.EOF
  16.             For Each x In rs.Fields
  17.                 Response.Write("<tr><td><b>" & x.name & "</b></td>")
  18.                 Response.write("<td>" & x.value & "</td></tr>")
  19.             Next
  20.             rs.MoveNext()
  21.         Loop
  22.  
  23.         Response.Write("</table>")
  24.     %>
  25.  
BODY

[HTML]<div id="Div1" align="center">
<asp:Label ID="lblSearch" runat="server" Font-Bold="True" Text="SEARCH"></asp:Label>
<br />
<br />
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<br />
<br />
<input type="BUTTON" value="SEARCH" onclick="Show(txtSearch.text)" id="btnSearch"/>
<br />
</div>

<div id="Div2"><b>Here...</b>
</div>[/HTML]
Sep 5 '07 #1
8 2583
dmjpro
2,476 2GB
Hye all..I'm Newbie..

I'm using asp.net..This code below I put in .aspx file..And become like that..
I want to make something like "WHEN USER PUT SOMETHING IN TEXTBOX AND CLICK THE BUTTON SEARCH..THE RESULT COMEOUT IN NEW ' div '..

I want to apply to my website..Using AJAX code..
I just copy the code from http://www.w3schools.com/ajax/ajax_database.asp.

Help me please..

HEAD

<%
Dim sql, conn, rs, x

Response.Expires = -1
sql = "SELECT * FROM the_TABLE WHERE the_COLUMN="
sql = sql & "'" & Request.QueryString("q") & "'"


conn = Server.CreateObject("ADODB.Connection")
conn.Provider = "Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.MapPath("../AJAXPage/db/Database1.mdb"))
rs = Server.CreateObject("ADODB.recordset")
rs.Open(sql, conn)
Response.Write("<table>")
Do Until rs.EOF
For Each x In rs.Fields
Response.Write("<tr><td><b>" & x.name & "</b></td>")
Response.write("<td>" & x.value & "</td></tr>")
Next
rs.MoveNext()
Loop

Response.Write("</table>")
%>

BODY

<div id="Div1" align="center">
<asp:Label ID="lblSearch" runat="server" Font-Bold="True" Text="SEARCH"></asp:Label>
<br />
<br />
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<br />
<br />
<input type="BUTTON" value="SEARCH" onclick="Show(txtSearch.text)" id="btnSearch"/>
<br />
</div>

<div id="Div2"><b>Here...</b>
</div>

Show us the Ajax Code and describe your specific Problem.
Then we able to solve your Problem.

Kind regards,
Dmjpro.
Sep 5 '07 #2
rempit
7
Sorry because I'm forgot to put full code..
So..Below I add the "JScript.js"..
The problem is error in JavaScript..

HEAD

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="JScript.js"></script>
  2.  
  3. <%
  4. Dim sql, conn, rs, x
  5.  
  6. Response.Expires = -1
  7. sql = "SELECT * FROM the_TABLE WHERE the_COLUMN="
  8. sql = sql & "'" & Request.QueryString("q") & "'"
  9.  
  10.  
  11. conn = Server.CreateObject("ADODB.Connection")
  12. conn.Provider = "Microsoft.Jet.OLEDB.4.0"
  13. conn.Open(Server.MapPath("../AJAXPage/db/Database1.mdb"))
  14. rs = Server.CreateObject("ADODB.recordset")
  15. rs.Open(sql, conn)
  16. Response.Write("<table>")
  17. Do Until rs.EOF
  18. For Each x In rs.Fields
  19. Response.Write("<tr><td><b>" & x.name & "</b></td>")
  20. Response.write("<td>" & x.value & "</td></tr>")
  21. Next
  22. rs.MoveNext()
  23. Loop
  24.  
  25. Response.Write("</table>")
  26. %>
BODY

[HTML]<div id="Div1" align="center">
<asp:Label ID="lblSearch" runat="server" Font-Bold="True" Text="SEARCH"></asp:Label>
<br />
<br />
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<br />
<br />
<input type="BUTTON" value="SEARCH" onclick="Show(txtSearch.text)" id="btnSearch"/>
<br />
</div>

<div id="Div2"><b>Here...</b>
</div>[/HTML]

JScript.js

Expand|Select|Wrap|Line Numbers
  1. // JScript File
  2. var xmlHttp
  3.  
  4. function Show(str)
  5. xmlHttp=GetXmlHttpObject();
  6. if (xmlHttp==null)
  7.   {
  8.   alert ("Your browser does not support AJAX!");
  9.   return;
  10.   } 
  11. var url="Default.aspx";
  12. url=url+"?q="+str;
  13. url=url+"&sid="+Math.random();
  14. xmlHttp.onreadystatechange=stateChanged;
  15. xmlHttp.open("GET",url,true);
  16. xmlHttp.send(null);
  17. }
  18.  
  19. function stateChanged() 
  20. if (xmlHttp.readyState==4)
  21. document.getElementById("Div2").innerHTML=xmlHttp.responseText;
  22. }
  23. }
  24.  
  25. function GetXmlHttpObject()
  26. {
  27. var xmlHttp=null;
  28. try
  29.   {
  30.   // Firefox, Opera 8.0+, Safari
  31.   xmlHttp=new XMLHttpRequest();
  32.   }
  33. catch (e)
  34.   {
  35.   // Internet Explorer
  36.   try
  37.     {
  38.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  39.     }
  40.   catch (e)
  41.     {
  42.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  43.     }
  44.   }
  45. return xmlHttp;
  46. }
Sep 5 '07 #3
dmjpro
2,476 2GB
You should maintain the Code tags while you do Post.
OK.

Expand|Select|Wrap|Line Numbers
  1. function stateChanged()
  2. {
  3. if (xmlHttp.readyState==4&&xmlHttp.status==200)
  4. {
  5. document.getElementById("Div2").innerHTML=xmlHttp.responseText;
  6. }
  7. }
  8.  
Only you checked that whether your page Loaded or not.
But you didn't check whether it is successful or not.
That's why I put one more condition xmlHttp.status==200.
It means your page successfully loaded.
And do one thing your page, which you call by Ajax, check that whether it runs successfully or not means it returns expected Output or not.
Good Luck with your Code.

Kind regards,
Dmjpro.
Sep 5 '07 #4
rempit
7
still having error..

"Unknown runtime error" in Head PART..Is it my mistake to call the database?
Sep 5 '07 #5
dmjpro
2,476 2GB
still having error..

"Unknown runtime error" in Head PART..Is it my mistake to call the database?
Look,
I am not a .NET Man, I am J2EE Man.
I think the error comes for your Head Part.
Means your Ajax call is made properly.
But on the Server Side the page you are calling that is the error.
First run it Separately, if it runs properly and shows Output properly then i think there will be no problem with your work.
Best of Luck with your try.

Kind regards,
Dmjpro.
Sep 5 '07 #6
rempit
7
Thanks dmjpro..
Thanks again for your help.. ;-)
Sep 5 '07 #7
dmjpro
2,476 2GB
Thanks dmjpro..
Thanks again for your help.. ;-)
Your Code is Working.
And no need to wish me Thanks.
You welcome always.

Kind regards,
Dmjpro.
Sep 5 '07 #8
acoder
16,027 Expert Mod 8TB
Changed thread title to describe the problem a little better. Extra question marks don't make the question any more urgent.

rempit, please use code tags in future when posting code. Thanks!

Glad you got your problem solved. Post again any time should you hit any more problems.
Sep 5 '07 #9

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

Similar topics

3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
3
by: Sheau Wei | last post by:
This is the search engine code that i create, but it was error and didnt come out the result. Cn u help me to check what wrong with my code? Thanks <Table cellspacing=1 cellPadding=1...
8
by: Steve H. | last post by:
Hello all, I am a visiting researcher at a laboratory this summer and my current task is investigating javascript obfuscation techniques. I am trying to get a relatively large sample of website...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.