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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:36:06+00:00 2026-05-11T19:36:06+00:00

I make an AJAX request to a PHP script which returns a number from

  • 0

I make an AJAX request to a PHP script which returns a number from a text file that changes. This AJAX request should happen every 3 seconds. However, an AJAX request is made once and it doesn’t return anything and firebug shows the AJAX GET request is still being made. After a few minutes it returns and produces a number. It should have made multiple calls but it only made one and it just came back with a final answer. I am struggling to figure out how this happened!? 🙁

//this is called first which calls getStatus which should get the progres of the
//conversion. This AJAX request takes a long time to come back which may hinder the
//getStatus coming back quickly maybe?
function convertNow(validURL){

       startTime = setTimeout('getStatus();', 6000);
       $.ajax({
       type: "GET",
       url: "main.php",
       data: 'url=' + validURL + '&filename=' + fileNameTxt,
       success: function(msg){  
       }//function     
     });//ajax

}//function convertNow

function getStatus(){

    $.ajax({
    type: "POST",
    url: "fileReader.php",
    data: 'textFile=' + fileNameTxt,
    success: function(respomse){
    textFileResponse = respomse.split(" ");
    $("#done").html("Downloading" + textFileResponse[0]);

    if(textFileResponse[0]=='100.0%'){
            $("#loading").hide("slow");
        $("#done").html("Complete");   
        return;
    }
        continueTime = setTimeout('getStatus();', 3000); 
    }
    });//ajax
}

The PHP script the second JavaScript function calls is this:

$fileName = $_POST['textFile'];
//calls an external script to get the text file output
$result = file_get_contents($_SESSION['serverURL']."fileReader.php?textFile=$fileName");
echo $result;

Is the above correct, and is my logic captured above? Or does the above mean only one AJAX request will be made?

This question is in relation to another question. A PHP script that I previously thought was slow. I am hoping the problem is JavaScript related now.

Thank you all for any help.

  • 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-11T19:36:06+00:00Added an answer on May 11, 2026 at 7:36 pm

    I was wondering whenever this code suppose to work at all. Let say the whole idea to implement something similar to this in Javascript is doubtful. First of all, because you don’t have any synchronization techniques in JavaScript at all, but in you code your are relying on particular order of execution of your code, which is not the case in 99%. By setting:

    setTimeout( "getStatus", 6000); 
    

    you create a kind of concurrency, therefore you can get the second script executed first, although you delayed it, but two requests can reach the server at the same time, so probably the second script will not return you anything, so the success function will not executed anymore.

    My hot advise to you consider redesign of your application, since the problem is definetely not in Javascript part at all.

    BTW, I think the use of $.ajax call has to be as:

    $.ajax({
    type: "POST",
    url: "fileReader.php",
    data: { param1: value1, param2:value2...etc},
    success: function(respomse){ ...}});
    

    PS. The fact that response take a lot of time to return point to the problem on server side and not in your code in Javascript. And if we started to talk about logging and you’ve mentioned firebug, you can use console.log( “msg”) to log into firebug console your messages.

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

Sidebar

Ask A Question

Stats

  • Questions 179k
  • Answers 179k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're using a FlowLayoutPanel, you could check whether the… May 12, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer Yes, it is allowed (if dangerous!). It's the actual write… May 12, 2026 at 3:56 pm
  • Editorial Team
    Editorial Team added an answer $newArray = array(); foreach ($array['root']['node'] as $node) { $newArray[ $node['value']… May 12, 2026 at 3:56 pm

Related Questions

I make an AJAX POST request to a PHP script on my server. That
I make an AJAX request to see if a sesion variable has been set.
I'm working at an app which would make a POST ajax request to a
I'm implementing a relatively simple autosave system and I'd like to do so using

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.