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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:16:28+00:00 2026-06-16T01:16:28+00:00

I am calling ajax after each 5 secs to update my data and I

  • 0

I am calling ajax after each 5 secs to update my data and I need to stop that call when a button is clicked.
My ajax function is:

function get_text(){
    var text = $.ajax({
            type: "POST",
            url: "getIt.php",
            async: false
        }).complete(function(){
            setTimeout(function(){get_text();}, 5000);
        }).responseText;

        $('#editor_Content').html(text);
}

this function is called at

$(document).ready(function(){
   new get_text(); 
}

I need to stop this call when a button is clicked and start this call again when the same button is clicked again. Any suggestions?

My button click code is

function editit(){ 
    var myVar = document.getElementById("editor_Content").getAttribute("contenteditable"); 
    if(myVar=='true'){         
        document.getElementById("editor_Content").setAttribute("contenteditable", "false"); 
        document.getElementById("editbtn").setAttribute("value","Edit Text"); 
    } else{ 
        document.getElementById("editbtn").setAttribute("value","Done Editing"); 
        document.getElementById("editor_Content").setAttribute("contenteditable", "true"); 
    } 
}
  • 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-16T01:16:30+00:00Added an answer on June 16, 2026 at 1:16 am

    You need to save the result of setTimeout and use it in a call to the clearTimeout function like so:

    function get_text(){
        var text = $.ajax({
            type: "POST",
            url: "getIt.php",
            async: false
        }).complete(function(){
            window.getTextTimeoutId = setTimeout(function(){get_text();}, 5000);
        }).responseText;
    
        $('#editor_Content').html(text);
    }
    
    $(document).ready(function(){
        get_text(); 
    } 
    
    function editit(){ 
        var myVar = document.getElementById("editor_Content").getAttribute("contenteditable"); 
        if(myVar=='true'){         
            if(window.getTextTimeoutId){
                window.clearTimeout(window.getTextTimeoutId)
                window.getTextTimeoutId = null;
            }
            document.getElementById("editor_Content").setAttribute("contenteditable", "false"); 
            document.getElementById("editbtn").setAttribute("value","Edit Text"); 
        } else{ 
            document.getElementById("editbtn").setAttribute("value","Done Editing"); 
            document.getElementById("editor_Content").setAttribute("contenteditable", "true"); 
            if(!window.getTextIntervalId) //edited for not to create another call. fixed!
                window.getTextTimeoutId = setTimeout(get_text, 0);
        } 
    }
    

    But for your purposes I think setInterval and clearInterval would work better. Here is what your new code would look like:

    function get_text(){
        var text = $.ajax({
            type: "POST",
            url: "getIt.php",
            async: false
        }).responseText;
    
        $('#editor_Content').html(text);
    }
    
    $(document).ready(function(){
         window.getTextIntervalId = window.setInterval(get_text, 5000); 
    } 
    
    function editit(){ 
        var myVar = document.getElementById("editor_Content").getAttribute("contenteditable"); 
        if(myVar=='true'){         
            if(window.getTextIntervalId){
                window.clearInterval(window.getTextIntervalId)
                window.getTextIntervalId = null;
            }
            document.getElementById("editor_Content").setAttribute("contenteditable", "false"); 
            document.getElementById("editbtn").setAttribute("value","Edit Text"); 
        } else{ 
            document.getElementById("editbtn").setAttribute("value","Done Editing"); 
            document.getElementById("editor_Content").setAttribute("contenteditable", "true");
            if(!window.getTextIntervalId) //edited for not to create another call. fixed!
                window.getTextIntervalId = setInterval(get_text, 5000);
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After an ajax call I am calling a function $this->widget('zii.widgets.CListView', array( 'viewData'=>array('sent'=>$sent), 'dataProvider'=>$dp, 'pager'
I am calling a php function using ajax call but its not working. I
I am calling a service that return JSON data. Script: $.ajax({ type: "POST", url:
Using PHP Zend Framework 2.0.2, I return JSON data after an AJAX call. Obviously,
$('#myhidde').attr(value,data[0]['MODE']); Iam calling ajax page which returns me json data after getting the data
I want to reset the form after calling an ajax function. This is the
I am calling a Web API through $.ajax() call. And I am getting the
Using the following JQuery/AJAX function I'm calling a partial view when an option is
html img returned from ajax has class of 'tocrop'. Currently I Calling the function
i'm trying to submit my Ajax form using jQuery. However calling the submit() function

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.