Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8220471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:31:44+00:00 2026-06-07T13:31:44+00:00

I am developing a .NET web application where I have to do ajax requests

  • 0

I am developing a .NET web application where I have to do ajax requests with the javascript function setInterval() to refresh the information of some pages.

With each ajax request I receive a xml response of about 68 KB that I manage to do visual changes in the html through jQuery. I set the interval to 2000 milliseconds but I would like, or rather, I am going to need to reduce it to 1000 ms.

Unfortunately, with each request the memory consum of the CPU increases and this provokes that the browser gets blocked and the user can’t use it unless he reloads the page. I have tested this in Firefox, Internet Explorer and Chrome but the result is always the same. If I don’t do setInvertal(), the problem disappear.

Also, I have been testing the scope of all my javascript variables but I haven’t found anything wrong and I suppose that Javascript has a efficient garbage collector to clean them.

I hope I have explained clear the issue. Does someone have some idea to resolve it?

Modified: I am using jQuery framework. My code is:

var tim;
$(document).ready(function () {
  tim = window.setInterval("refresh()", 2000);
});

function refresh() {
   $.post("procedures.aspx", $("#formID").serializeArray(), function (data) {
     if (data != ""){
       var xml = $.parseXML(data);

       ... (read and process xml to do changes in the html)

     }
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:31:47+00:00Added an answer on June 7, 2026 at 1:31 pm

    You haven’t posted any code snippet for inspection, so my answer is based on an error commonly made when creating such “polling” functions. I’m also assuming that you are doing things manually, without using frameworks like jQuery or MooTools.

    Your problem is most likely to be caused by creating new a XMLHttpRequest object in each polling call, instead of creating one such instance outside of setInterval, and opening and using this time and again.

    Basically, you may be writing your code like this:

    var pollInterval = setInterval(function() {
        var xhr = new XMLHttpRequest(); //ouch, this hurts!
        xhr.open('GET', 'url', true);
        xhr.send();
        //etc.
    }, 2000);
    

    If this is the case, merely move the XMLHttpRequestObject creation out of the polling loop to ensure that you use the same object again and again, thereby preventing a memory leak of sorts (if I may call it that).

    var xhr = new XMLHttpRequest(); //now we can re-use this!
    var pollInterval = setInterval(function() {
        xhr.open('GET', 'url', true);
        xhr.send();
        //etc.
    }, 2000);
    

    Again, you haven’t posted any code snippet, or details of any frameworks you may be using. So what I’m suggesting is based on an error I’ve encountered frequently when inspecting polling ajax code. Hope this helps. If not, do edit the question and post some code.

    Disclaimer: I used only the XMLHttpRequest object for brevity, not vendor hate (or love). You’ll obviously use a cross-browser request object instantiation function, or better still a library which abstracts away these gory details.

     

    Updates


    So, your code needs to update the dom every two seconds? For as long as the page is loaded? Wihout ever stopping? I thought I’d see a clearInterval somewhere, but anyways.

    This is a bit awkward. The closest I’ve gotten to such a situation is when I needed to code a pulse line, based on a ticker API, for diplaying a real-time (ok, pseudo-realtime at 1s) graph. The good part in my case was that the API was blazing fast, with super low latency, the data I received was a mere float, and the dom manipulation I did with it was of negligible space-time complexity.

    My concern here is that if the server doesn’t respond in two seconds, or if it does close to two seconds, then you have a piece of complex code which is already eating in significant milliseconds of those two second intervals. The dom may not update every two seconds!

    1. Hygienic tip: Get rid of the quotes in
      window.setInterval("refresh()", 2000). It should just be
      window.setInterval(refresh, 2000) Reasons are here: Memory leak for javascript setInterval

    2. So, $.post will definitely create new XHR objects every two seconds,
      as per the code. Realistically, what are the server response times
      like? How many times does setInterval loop? For low counts, say for
      response times below 10 seconds, new XHRs should not be ‘THE’
      problem.

    3. 500 line XML parsing? Each interval? Sounds painful to me. Will it
      be possible for you to tokenize the XML into a JSON string on the
      server, and return this string to the UI? It will save client CPU cycles
      for sure.

    HTML with 11000 lines. So that’s a lot of dom traversal and manipulation. Here’s a small checklist:

    1. Are you using best selectors? (speficity of your xpath expressions). Shizzle has you covered there, but do the best you can. Things like $(‘p *’) can wreck havoc.
    2. Have you minimized document reflow?
    3. Loops: Using for, or mapped functions over arrays are the best (most
      efficient)

    4. Property access: Are you cutting down on repeated nested property
      access, and using one-off references for efficiency?

    5. Appending/Manipulating efficiency: For example: do you append
      individual list items? Ideally you should append the whole list
      chunk in one go. Same for deletions etc. Basically, chunky one-time
      manipulations instead of repeated manipulations.

    Difficult to nail this one, without understanding the low level intentions and mechanics of your use-case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a web application using .net/c#/jQuery. I want to develop an AJAX function
I am developing an ASP.NET web application and I have some images in the
I'm developing an asp.net web application and I have some image button controls, how
I am developing an ASP.NET web application that incorporates google maps. I have an
Age old question! When you have finished developing and testing your ASP.Net web application,
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I am developing a mobile web application in asp.net. I have a button in
We will be developing 3 asp.net web applications. Each of them will have it's
I have a project (Web Application) which I have been developing in C#/ASP.NET, and
I have been developing a web application with asp.net and I have smoe question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.