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

ASP and AJAX problems

Hello,

I am having problems with using AJAX to call information to my primary ASP page from a secondary asp page that brings in the data I want to display.

I'm having the onfocus event trigger the function show() to call in the data from the secondary asp page. However, when I click on the record in the list, nothing happens. The information is suppose to appear ni the div id = "div_id". Please help. I need the information in the secondary asp page to appear in the primary asp page.

Relevant part of primary asp page:

Expand|Select|Wrap|Line Numbers
  1. <table width="786" height="215" border="0" cellspacing="0">
  2.   <tr>
  3.     <td width="183" height="213" align="center" valign="top">
  4.     <table width="183" height="196" border="0" cellspacing="0">
  5.       <tr>
  6.         <th height="27" bgcolor="#0099FF" align="center">&nbsp;</th>
  7.       </tr>
  8.       <tr>
  9.         <th height="12" bgcolor="#0099FF" align="center">List Heading</th>
  10.       </tr>
  11.       <tr>
  12.         <td valign="top" align="center"><form id="form3" name="form3" method="get">
  13.         <select name="selectlist" size="10" id="list"onfocus="show(this.value)">
  14.           <%while not rsS.eof%>
  15.           <option id="<%=rsS("ID")%>"><%= rsS("Name") %></option>
  16.           <% rsS.movenext
  17.              wend%>
  18.         </select>
  19.         </form></td>
  20.       </tr>
  21.     </table>
  22.     </td>
  23.     <td width="486" valign="top"><table width="597" border="1" cellspacing="0">
  24.       <tr>
  25.         <th colspan="4" scope="col" bgcolor="#0099FF">Display Heading 1</th>
  26.         <th scope="col" bgcolor="#0099FF">Display Heading 2</th>
  27.       <tr>
  28.         <th width="9%" height="23" bgcolor="#0099FF"><em>Column1 Heading</em></th>
  29.         <th width="9%" bgcolor="#0099FF"><em><strong>Column2 Heading</strong></em></th>
  30.         <th width="30%" bgcolor="#0099FF"><em><strong>Column3 Heading</strong></em></th>
  31.         <th width="26%" bgcolor="#0099FF"><em><strong>Column4 Heading</strong></em></th>
  32.         <th width="26%" bgcolor="#0099FF">&nbsp;</th>
  33.       </tr>
  34.     </table><div id="div_id"></div>
  35.     </td>
  36.   </tr>
  37. </table>

JavaScript (js) page

Expand|Select|Wrap|Line Numbers
  1. // JavaScript Document
  2.  
  3. var xmlHttp
  4.  
  5. function show(str)
  6. xmlHttp=GetXmlHttpObject();
  7. if (xmlHttp==null)
  8.   {
  9.   alert ("Your browser does not support AJAX!");
  10.   return;
  11.   } 
  12. var url="primaryasppage.asp";
  13. url=url+"?variable="+str;
  14. url=url+"&sid="+Math.random();
  15. xmlHttp.onreadystatechange=stateChanged;
  16. xmlHttp.open("get",url,true);
  17. xmlHttp.send(null);
  18. }
  19.  
  20. function stateChanged()
  21. if (xmlHttp.readyState==4)
  22. document.getElementById("div_id").innerHTML=xmlHttp.responseText;
  23. }
  24. }
  25.  
  26. function GetXmlHttpObject()
  27. {
  28. var xmlHttp=null;
  29. try
  30.   {
  31.   // Firefox, Opera 8.0+, Safari
  32.   xmlHttp=new XMLHttpRequest();
  33.   }
  34. catch (e)
  35.   {
  36.   // Internet Explorer
  37.   try
  38.     {
  39.     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  40.     }
  41.   catch (e)
  42.     {
  43.     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  44.     }
  45.   }
  46. return xmlHttp;
  47. }
Here is the secondary asp page code.

Expand|Select|Wrap|Line Numbers
  1. <% 
  2. Set rs = Server.CreateObject("ADODB.Recordset")
  3.         rs.ActiveConnection = "dsn=dsn;uid=user;pwd=pwd;database=db;"
  4.         rs.CursorType = 0
  5.         rs.CursorLocation = 3
  6.         rs.LockType = 1
  7.         rs.Source = ("Stored Procedure @SQLVariable= '" & request.QueryString("variable") & "'")
  8.         rs.Open()
  9.  %>
  10. <% while not rs.eof%>
  11. <% response.Write("<tr>") %>
  12. <% response.Write("<td>") %><%= rs("column1") %><% response.Write("</td><td>")%><%= rs("column2") %><% response.Write("</td><td>")%><%= rs("column3") %> <% response.Write("</td><td>")%><%= rs("column4") %><% response.Write("</td><td> &nbsp; </td>")%>
  13. <% response.Write("</tr>") %>
  14. <% rs.movenext %>
  15. <%wend%>
Thanks.
Mar 6 '08 #1
4 1420
markrawlingson
346 Expert 100+
This can happen if there's a problem with the AJAX response, like a 404 or an error within the ASP script you're trying to call.

In the below code

Expand|Select|Wrap|Line Numbers
  1. function stateChanged() {
  2.    if (xmlHttp.readyState==4) {
  3.       document.getElementById("div_id").innerHTML=xmlHttp.responseText;
  4.    }
  5. }
  6.  
You should put in some error handling..
Expand|Select|Wrap|Line Numbers
  1.    function stateChanged() {
  2.       if (xmlHttp.readyState==4) {
  3.          document.getElementById("div_id").innerHTML=xmlHttp.responseText;
  4.       } else if(xmlHttp.readyState == 4 && xmlHttp.status != 200) {
  5.          document.getElementById("div_id").innerHTML= 'ERROR! See Below! <br /><br />' + xmlHttp.responseText;
  6.       }
  7.  
So if the page throws a 404, for instance, the div layer will be filled in with something like page cannot be displayed. If it's a scripting error in the page you're trying to call, the div will be filled in with the vbscript error information. Once you get this, if you still can't figure it out.. write back with the error and we'll take it from there :)
Sincerely,
Mark
Mar 6 '08 #2
DrBunchman
979 Expert 512MB
Another possibility is that the contents of your second page is not displaying because the recordset you create there is not returning any rows.

Have you tried replacing the contents of your secondary page with a simple

<% Response.Write("variable=" & Request.QueryString("variable")) %>

to make sure that your data is being passed correctly and to test whether your AJAX call is working at all?

I'd definitely put in the error trapping as Mark said because, although I've tested your script and it worked correctly for me, different browsers handle AJAX differently.

Let us know how you get on.

Dr B
Mar 7 '08 #3
This can happen if there's a problem with the AJAX response, like a 404 or an error within the ASP script you're trying to call.

In the below code

Expand|Select|Wrap|Line Numbers
  1. function stateChanged() {
  2.    if (xmlHttp.readyState==4) {
  3.       document.getElementById("div_id").innerHTML=xmlHttp.responseText;
  4.    }
  5. }
  6.  
You should put in some error handling..
Expand|Select|Wrap|Line Numbers
  1.    function stateChanged() {
  2.       if (xmlHttp.readyState==4) {
  3.          document.getElementById("div_id").innerHTML=xmlHttp.responseText;
  4.       } else if(xmlHttp.readyState == 4 && xmlHttp.status != 200) {
  5.          document.getElementById("div_id").innerHTML= 'ERROR! See Below! <br /><br />' + xmlHttp.responseText;
  6.       }
  7.  
So if the page throws a 404, for instance, the div layer will be filled in with something like page cannot be displayed. If it's a scripting error in the page you're trying to call, the div will be filled in with the vbscript error information. Once you get this, if you still can't figure it out.. write back with the error and we'll take it from there :)
Sincerely,
Mark
No. I'm not get any errors, I'm not getting anything at all in the div.

Should the listbox read like this?
[code]
"><form id="form3" name="form3" method="get">
<select name="selectlist" size="10" id="list"onfocus="show(<%=rsS("ID")%>)">
<%while not rsS.eof%>
<option id="<%=rsS("ID")%>"><%= rsS("Name") %></option>
<% rsS.movenext
wend%>
</select>
</form>
[code]
Mar 10 '08 #4
Thank you to both of you for your help. I did get it to work and it works beautifully now. I managed to fool with it and found out that I did not have the some things done correctly, like using the value of the listbox option instead of the id for it and I changed the div to a span. Thanks again.
Mar 13 '08 #5

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

Similar topics

11
by: Yarco | last post by:
I want to use "Ajax" to create my web for hobby. But i don't know whether "Ajax" is mature... And what about with php? Someone have experience on it? ....
4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
8
by: needin4mation | last post by:
I understand this is a asp.net group, but thought I would post this here for comments. I admit I have used this post in another group, but it has less traffic. Here's to hoping I'm just blind to...
11
by: John Smith | last post by:
I am using Ajax to refresh a DIV area by setting the innerHTML=request.responseText in the usual manner. in the response text I have a <SCRIPT> tag in line, but this is not executed. Is there a way...
0
by: melledge | last post by:
Ajax Developers' Day added to XTech 2006 agenda XTech 2006 - 17-19 May - Hotel Grand Krasnopolsky - Amsterdam, The Netherlands
10
by: Steve | last post by:
I need to build a very dynamic client and would be interested in knowing the pros and cons of using JSF and Ajax to accomplish this. Thanks. Steve
0
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly...
31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
3
by: =?Utf-8?B?bWNpbWFnaW5n?= | last post by:
We have recently applied AJAX to our web site, nothing particularly fancy, just some update panel, progress images and collapsible panels, just the basics to improve the user experience. The...
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: 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...
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...

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.