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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:39:25+00:00 2026-05-15T09:39:25+00:00

I have a continous ajax request asking for some data that is to be

  • 0

I have a continous ajax request asking for some data
that is to be displayed in textarea.
Now my problem, how do I display the data as soon as page is loaded.

My template code is as follows:




     <html>
<head>
<script type="text/javascript" src="/jquerycall/"></script>
<script type="text/javascript">
     $(document).ready(function()
     {
               var setid = 0;
               var s = new String();
               var my_array = new Array();
               var no_of_lines = 0;
               var array_copy = new Array();
               var fname ="{{fname}}"
               var pid = "{{pid}}"
               function displayfile()
               {

                var text = $("#textid").val();
                if(text == "")
                {
                         no_of_lines = 0;
                }
                else
                {

                        array_copy = text.split("\n");
                        no_of_lines = array_copy.length;


                }
                /*$("#tid").val(no_of_lines)*/
                $.ajax({
                                type:"POST",
                                url:"/displayoutput/",
                                datatype:"json",
                                data:{text:no_of_lines,filename:fname,pid:pid},
                                success:function(data)
                                        {

                                                s = data.filedata;
                                                if(s == "")
                                                {
                                                   clearInterval(setid);

                                                }
                                                my_array = s.split("\n");
                                                displaydata(my_array);

                                        }


                        });


              }

                    function displaydata(my_array)
              {

                   var i = 0;
                   var length = my_array.length;
                   for(i=0;i<my_array.length;i++)
                   {
                       var line = my_array[i] + "\n";
                       line = line.replace(/</g,"&lt;");
                       $("#textid").append(line);
                       $("#tid").val(line)

                   }


             }


              $("form").submit(function(event)
              {

                    setid = setInterval(displayfile,1000);
                    event.preventDefault();

              });

              $("#stop").click(function()
              {
                    clearInterval(setid);
              });
     });

</script>
</head>
<body>
<form method="post">
<input type="submit" value="Click Me"/><br><br>
<button type="button" id="stop">Stop</button><br><br>
<textarea id="textid" disabled="true" readonly="true" rows=30 cols=100></textarea><br><br>


</form>
</body>
</html>



Here, the data is loaded when I click the "Click Me"
But I want the data to be loaded as soon as page is loaded
Any suggestions will be valuable
Thanks in advance 

tazim

  • 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-15T09:39:25+00:00Added an answer on May 15, 2026 at 9:39 am

    Just call displayfile(); within your .ready() handler.

    If you don’t wait to lose one second, modify your code like this:

    $("form").submit(function(event)
    {
           setid = setInterval(displayfile,1000);
           event.preventDefault();
    }).submit();
    

    Or.. just put displayfile(); anywhere in your ´.readyhandler to execute that ajax
    request as soon as possible (after the
    DOM` is ready);

    If you don’t need the DOM to be ready you can execute that function even further by creating a selfexecuting anonymous function.

    (function(){
        // code to execute
    })();
    

    You can fill that with the code from your displayfile() function and it will execute
    asap.

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

Sidebar

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.