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 6251875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:41:40+00:00 2026-05-24T13:41:40+00:00

var hasData = ‘1’; while (hasData != 0) { $.ajax({ url: ‘/ajax.php?updateRow=’+hasData, dataType: ‘json’,

  • 0
       var hasData = '1';
        while (hasData != 0) {
            $.ajax({
            url: '/ajax.php?updateRow='+hasData,
            dataType: 'json',
            async: false,
            success: function(data) {
                hasData = data.next;
                $('.result').append(data.html);
              }
            });

What should happen:
JSON Array pulled from PHP ( [html] and [next] ). If [next] is set to 0 (when there are no more entries) – the while loop stops and that should be it.

What happends:
Everything that should, except – when the while() requirement is met (so when hasData is set to 0) – the loop enters into an infinite loop (and it keeps requesting the last entry, forever…until the script becomes “unresponsive”)

  • 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-24T13:41:42+00:00Added an answer on May 24, 2026 at 1:41 pm

    ajax sends a request and executes the callback when there is a response. So what’s happening is:

    • fire a request
    • fire another request
    • fire another request
    • fire another request
    • …

    because it’s inside a while loop. You’re clogging your script up with requests, and the server gets a bunch of requests which it probably cannot handle.

    Edit: I’m sorry, I missed async: false. However that always makes the browser irresponsive. The best thing to do would be using async: true and fire another if the conditional says so, but only after you get the response:

    function check() {
            $.ajax({
            url: '/ajax.php?updateRow='+hasData,
            dataType: 'json',
            async: true,
            success: function(data) {
                hasData = data.next;
                $('.result').append(data.html);
                if(hasData != 0) check(); // do it again
              }
            });
    }
    
    check(); // fire the first request
    

    As Spycho pointed out, since you’re fetching JSON, a more convenient way might be:

    (function() {
    
        var fireRequest = function() { // this function is not available anywhere else,
                                       // to avoid having this process running more than once
    
            $.getJSON('/ajax.php', {updateRow: hasData}, function(data) {
                hasData = data.next;
                $('.result').append(data.html);
                if(hasData != 0) fireRequest(); // do it again
            });
    
        };
    
        fireRequest(); // start the process
    
    })(); // call it
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var htm = $.ajax({ type: GET, url: ./viewforms, async: false }).responseText; var myObject =
var err = ''; err += 'err a'; myString = 'Blah'; new Ajax.Request('/check_me.php', {
var Box = function(){ this.parm = {name:rajakvk,year:2010}; Box.prototype.jspCall = function() { $.ajax({ type: post,
var AppPatientsList = JSON.parse(JSON RESPONSE); var AppPatientsListSort = AppPatientsList.sort(function(a,b){ return a.firstName.toLowerCase() <b.firstName.toLowerCase() ? -1
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();
var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
var query1 = urlencode($('input[name=searchTerm]').val()); //user1 $.getJSON('http://twitter.com/friends/ids.json?screen_name='+ query1 +'&jsoncallback=?', function(data){ $('content').append(''+data.length+''); }); This is a
var ajaxRequestqqq; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox,
var selValues = {}; selValues['234'] = $('#asd').val(); selValues['343'] = function () { var el
var buffer = new byte[short.MaxValue]; var splitString = new string[] {\r\n}; while (_tcpClient.Connected) {

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.