473,661 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP and AJAX problems

14 New Member
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 1428
markrawlingson
346 Recognized Expert Contributor
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 Recognized Expert Contributor
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.QuerySt ring("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
srkidd12
14 New Member
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="selectlis t" size="10" id="list"onfocu s="show(<%=rsS( "ID")%>)">
<%while not rsS.eof%>
<option id="<%=rsS("ID" )%>"><%= rsS("Name") %></option>
<% rsS.movenext
wend%>
</select>
</form>
[code]
Mar 10 '08 #4
srkidd12
14 New Member
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
2333
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
4308
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 from within an inline function. Within the AJAX object: this.xmlhttp = new XMLHttpRequest(); this.response = ''; //to contain the response text OR xml var that = this; //since we cannot reference this within the
8
1769
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 the obvious: I have been reading a lot about AJAX. I want to use it and will. But I keep reading about how it doesn't make a roundtrip to the server, no postback, etc. But isn't the truth that *something* makes a trip to the server? It may...
11
3130
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 of making the ajax refresh process this. Thanks Mike
0
1840
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
6303
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
1830
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 developing world of Ajax user interfaces on the browser, IDEAlliance (www.idealliance.org) announced today that its annual XTech Conference will kick off on May 16 with Ajax Developers' Day. XTech 2006 (www.xtech-conference.org), to be held May...
31
3111
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 around here? If so, do you know if Ajax.NET can be used without prototype.js? -- "The most convoluted explanation that fits all of the made-up facts is the most likely to be believed by conspiracy theorists. Fitting the
23
5009
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 from another HTML page viewed in IE7, that is also UTF-8 encoded (search for "china" on google.com). I paste the chineese chars into a content editable div. My Ajax webservice compiles an XML where the data from the content editable div is...
3
11084
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 project has gone fantastically well except we have ran into a strange error when accessing the site from inside of one of our client networks. All the pages load fine without any problems, but if you try and press any buttons on an AJAX enabled...
0
8432
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
8855
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
8758
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...
1
8545
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7364
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
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2762
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
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.