DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Strange AJAX Behavior

  1. #1
    Join Date
    Feb 2009

    Strange AJAX Behavior

    I am not certain how much code is needed to explain this oddity so I will try to keep it to a minimum, as the resolution may be something obvious I am missing.

    I am writing a feed reader and have the feed summary information within one div and the feed information within another. The feed summary information shows the number of unread messages. When I click the "Mark As Read" link in the feed information, the appropriate row in the database is updated, an alert box pops up announcing that the item has been marked as read, and the feed summary information is read and displayed.

    Here is the abbreviated code:
    function MarkRead(Item, Feed, Flag) {
      URL = 'MarkRead.asp?I=' + Item + '&F=' + Flag;'get', URL, true)
      xmlHttp.onreadystatechange = UpdatePage;
    alert("Item marked as read.");
    function UpdatePage() {
      if (xmlHttp.readyState == 4) {
        var response = xmlHttp.responseText;
        document.getElementById('FeedDisplay').innerHTML = response;
    function ReadFromDatabase(Feed,ReadAll) {
      URL = 'ReadFromDatabase.asp?F=' + Feed + '&RA=' + ReadAll;'get', URL, true)
      xmlHttp.onreadystatechange = UpdatePage;
    function UpdateSummary() {
      URL = 'ReadSummary.asp'; // Only get the most recent 100 items'get', URL, true)
      xmlHttp.onreadystatechange = UpdateSummarySection;
    function UpdateSummarySection() {
      if (xmlHttp.readyState == 4) {
        var response = xmlHttp.responseText;
        document.getElementById('SummaryInfo').innerHTML = response;
    This works just fine.

    The alert box, oddly enough, appears to be a necessary element. If I remove the alert box then the information is not written to the feed information section. I can also put the alert box within the ReadFromDatabase() function and everything works fine. However, removing it returns me to the original problem.

    Any ideas what might be going on here? I am in the process of learning AJAX and apparently I am missing something somewhere.

    Whatever help can be offered would be greatly appreciated.

    Cheers -

    Last edited by Hack; 03-24-2009 at 09:55 AM. Reason: Added Code Tags

  2. #2
    Join Date
    Jan 2005
    this is a longshot but try putting a semicolon after this line, ReadFromDatabase(Feed);
    I know JavaScript is not a strongly typed language, but I have seen instances in which the omission of a semicolon, particularly when it's included on every other line, has caused problems.

  3. #3
    Join Date
    Mar 2007
    Bangalore, India
    You are reusing the same xmlHttp variable for all requests. So, what happens is, before you get the response of the xmlHttp, you have changed the handler and just about everything for that XMLHttpRequest object. You should make separate objects for each call, and wait for the response of one request before you issue the next one. To do that, instead of calling all the methods (the ReadFromDatabase and UpdateSummary) in the first function, call these from the onsuccess handlers of the previous call.

Similar Threads

  1. Replies: 1
    Last Post: 09-11-2008, 07:30 PM
  2. Ajax calendar extender behavior
    By smakawhat in forum AJAX
    Replies: 0
    Last Post: 07-10-2007, 11:13 AM
  3. Replies: 7
    Last Post: 08-15-2006, 03:21 PM
  4. strange behavior...related to same question...
    By Chris Hylton in forum VB Classic
    Replies: 0
    Last Post: 06-10-2002, 11:31 AM
  5. Strange behavior
    By Paul in forum VB Classic
    Replies: 0
    Last Post: 10-18-2001, 02:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center