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

Problem Referencing Function in AJAX Application.

Can someone kindly explain how to properly call JavaScript functions in the following scenario...

Expand|Select|Wrap|Line Numbers
  1. #...XMLHttpRequest Object has been created outside the loop e.t.c.
  2.  
  3. for(var cnt=0; cnt < 5; cnt++)
  4. {
  5. #...some code here
  6.  
  7. ajaxObj.open("GET", url, true); 
  8. ajaxObj.onreadystatechange = dispValue; # Line 200: Problem Point
  9.  
  10. #Another option I tried - function(){dispValue();}; #Line 210
  11. ajaxObj.send(null);
  12.  
  13. function dispValue()
  14. {
  15.  if(ajaxObj.readyState == 4)
  16.   {
  17.   if(ajaxObj.status == 200)
  18.     {
  19.     var resp = ajaxObj.responseText;
  20.     #resp += resp; #Line 250
  21.     alert(resp);
  22.     }
  23.   }
  24. }
  25.  
1. I have used the method on line 200 in some other parts of the application and it works fine. However, this line keeps returning an error of dispValue is not defined with Firebug, IE does nothing.

2. Is my alternative on line 210 allowed?

3. The second problem is on line 250, where I want to add the responseText repeatedly in the loop. The responses are numbers e.g. 45, 72, 23.

Please ignore the wrong ordering of line numbers - it was just for clarity.


Development Platform
- Windows XP Home Edition
- Firefox/ Firebug, IE and Opera browsers
- PHP, MySQL
Nov 23 '07 #1
1 1045
acoder
16,027 Expert Mod 8TB
Since Ajax is asynchronous, you won't have control over the order.

To do that, make the request when the first request has reached readyState 4.

You're reusing the same ajax object. You'll need to create new ones to use 5 at the same time.
Nov 26 '07 #2

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

Similar topics

42
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox...
2
by: Alex | last post by:
Example uploaded to: http://www.clickatus.com/ajax/ BTW - This is for FIREFOX, won't work in IE. I don't know why but when it is executed the browser still in loading state... Even though...
1
by: vachacz | last post by:
hi i'm struggling with integration of a js class aimed for ajax handling with fireing actions from the class. here's my code sample: function AjaxLibLoad(httpActionParam, targetLayerParam){...
1
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been...
3
by: Alok yadav | last post by:
I have an open IP and on that IP our main application is hosted. it uses ajax. in web.config file i have register ajax handlers. there are also other sites or project on that IP. now my problem is...
1
by: quill | last post by:
Hi I am making a chatroom script and it appears that the problem seems to be that my setTimeout's are conflicting. The logic is as follows: Run a login check every x seconds Run a trigger...
3
by: nicksname7 | last post by:
Hi, I am a newbie in the AJAX world. first of all, take a look at my script first: assume this script is saved as "myAjax.js" //-----------------inside myAjax.js-------------------- function...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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
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: 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...

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.