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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:25:52+00:00 2026-06-10T01:25:52+00:00

When a button is clicked I have a jquery AJAX call such as: $(.play).click(function(){

  • 0

When a button is clicked I have a jquery AJAX call such as:

$(".play").click(function(){
    function doAjax(){
        $.ajax({
        url: 'blah.php',
        success: function(data) {
            if (data==250)
            {
                setTimeout(doAjax, 2000);
            }
            else
            {
                $('#quote p').html(data);
            }

        }
        });
    }
    doAjax();
});

Any data from the server is printed to the div:

<div id="quote"><p> </p></div>

blah.php on the server does some processing to retrieve some status codes:

$r = new HttpRequest('http://localhost...', HttpRequest::METH_GET);
$r->send();

if ($r->getResponseCode() == 200)
{
echo "Starting video..."        
//sends a video to play
}
else if ($r->getResponseCode() == 450)
{
    echo "Oops! Not found...";
}
else if ($r->getResponseCode() == 550)
{
    echo "Oops! An error occurred...";
}
else if ($r->getResponseCode() == 250)
{
    echo "Initializing...";
}
else
{
    echo "Now we are in trouble";
}

The response codes ($r->getResponseCode()) get returned as I expect, so my problem is with my repeated ajax call with setTimeout. What I want to happen is that when code 250 is returned it prints out Initializing, which it does, but then my AJAX call will repeat because the success function is called with 250. This doesn’t work. It says Initializing but never repeats, because the next step is that I should see Starting video....

Everything else seems to check out, I guess the problem is with my jquery success function?

  • 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-10T01:25:54+00:00Added an answer on June 10, 2026 at 1:25 am

    The problem here is that the “data” variable that you have access to in Javascript is actually the exact text that you’re echoing in your PHP file, blah.php.

    So a more accurate way of making it work is checking if data == “Initializing…”. You may also want to consider outputting JSON-compatible text from your PHP file so that you can get both a status code and a message.

    Consider putting this as your PHP:

    $code = $r->getResponseCode();
    $message = "";
    
    switch($code) {
        case 200:
            $message = "Starting video...";
            break;
        case 450:
            $message = "Oops! Not found...";
            break;
        case 550:
            $message = "Oops! An error occurred...";
            break;
        case 250:
            $message = "Initializing...";
            break;
        default:
            $message = "Unknown status";
            break;  
    }
    
    print "{ 'code': $code, 'message': '$message' }";
    

    The above will output all the data you need, in JSON format.

    In your javascript, consider using jQuery’s built in getJSON method, and parse the data as a regular javascript object.

    $.getJSON('blah.php', function(data) {
            if (data['code'] == 250)
            {
                setTimeout(doAjax, 2000);
            }
            else
            {
                $('#quote p').html(data['message']);
            }
    
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this button, and when clicked, it sends an ajax call which changes
I am using jQuery to call a function when a button is clicked. This
i have a problem with this jquery, in the success function call, its mean
I have a form using jquery validation plugin. My submit button has an ajax
I have a dropdown list which is populated via a jquery ajax call when
For some reason, jQuery isn't loading my php file. The button is clicked and
I have custom server control contains templatefield when an out button clicked the field
I have a windows form simply like this: 1) a button when clicked will
I have a usercontrol that hides a div when a button is clicked. <asp:LinkButton
I have a button that when clicked will run a stored procedure on a

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.