Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
How to keep scroll position when refreshing a partial page?

I have a table in a partial view which refreshes every 5 seconds. The problem is that when it refreshes it goes back to the top and I would like to keep the same position as before refresh.

I've researched and I know that I can achieve this with something like this:

var scrollPosition = $(window).scrollTop();
// Your ajax polling code, on success you do the code below.
$(window).scrollTop(scrollPosition);

The problem is I can't figure out where exactly to incorporate this code and what it should look like as a whole.

My code is below:

<div class="row">
        <div class="col-md-12">
            <div class="row">
                <div class="col-md-12" id="refresh">
                    @Html.Action("EntryEventUser", "Home"),
                </div>
            </div>
            <script>
                function loadPartialView() {
                    
                   $.ajax({
                    url: "@Url.Action("EntryEventUser", "Home")",
                    type: 'GET', // <-- make a async request by GET
                    dataType: 'html', // <-- to expect an html response
                    success: function(result) {
                    $('#refresh').html(result);
                       }
                });
                }
                
            $(function() {
                var scrollPosition = $("loadPartialView").scrollTop();
                loadPartialView(); // first time

               // re-call the function each 5 seconds
                window.setInterval("loadPartialView()", 5000);
                $("loadPartialView").scrollTop(scrollPosition);
            });
             
            </script>
            <script>
                function myFunction() {
                    var input, filter, table, tr, td, i;
                    input = document.getElementById("myInput");
                    filter = input.value.toUpperCase();
                    table = document.getElementById("myTable");
                    tr = table.getElementsByTagName("tr");
                    for (i = 0; i < tr.length; i++) {
                        td = tr[i].getElementsByTagName("td")[0];
                        if (td) {
                            if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                                tr[i].style.display = "";
                            } else {
                                tr[i].style.display = "none";
                            }
                        }
                    }
                }
            </script>
        </div>
    </div>
</div>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!