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

  • SEARCH
  • Home
  • 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 1958644
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T08:23:19+00:00 2026-05-17T08:23:19+00:00

I am trying to use ajax to update the views which simply checking results

  • 0

I am trying to use ajax to update the views which simply checking results in database

if there are results found, my html div will updated with

section in that div
if not found result, it will check after some time.

the code is working without if else section

but the client browser will crash at the certain point, the browser is frozen (seems if i change cache into True, it works fine, is that right?)

my if else statement using for judging if i should updating again. logic is if my html div got

segment i will stop updating.

<script>
        function updateResults() {
            $.ajax({
                type: 'GET',
                url: "/sResultsView",
                cache: true,
                success: function(html){
                    $("#resultsDiv").html(html);
                } 
            });
            window.setTimeout('updateResults()', 4000);
        }
        if($'#resultsDiv:not(:has(p))'){
            updateResults();
        }else {
            return;
        }
        }
    </script>

however, it keep telling me syntax is wrong in if else, it is the first time i write ajax

any suggestion? am i doing right? or any better ideas?

many thanks in advance

  • 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-05-17T08:23:23+00:00Added an answer on May 17, 2026 at 8:23 am

    Currently you’re creating an infinite loop (or would be), instead schedule the check inside your success callback, like this:

    function updateResults() {
      $.ajax({
        type: 'GET',
        url: "/sResultsView",
        cache: true,
        success: function(html){
          $("#resultsDiv").html(html);
          if($('#resultsDiv p').length == 0) //if not found, run again in 4 seconds
            window.setTimeout(updateResults, 4000);
        } 
      });
    }
    

    For completeness sake, your syntax error is in the if statement missing patenthesis, here:

    if($('#resultsDiv:not(:has(p))')){
        ^ ------- missing --------- ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use AJAX polling with jQuery to update a span element
I am trying to use jQuery's ajax functionality to update data from a web
I am trying to use an Ajax (I think) call to update my model
Im trying to use AJAX to update a partial on a page. I following
I am trying to use AJAX for a web app game that im making.
I am currently trying to use AJAX in my application via jRails. I am
I am trying to use .ajax() to post a People object to a MVC2
I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method
I am using HMVC codeigniter. I am trying to use jquery ajax first time.
I am trying to use periodic refresh(ajax)/polling on my site by XMLHttp(XHR) to check

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.