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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:09:14+00:00 2026-06-15T07:09:14+00:00

Below is my code: (function worker() { oTable = $(‘#example’).dataTable({iDisplayLength : 25, sAjaxSource: /getservicevers/?value=

  • 0

Below is my code:

(function worker() {
oTable = $('#example').dataTable({"iDisplayLength" : 25, "sAjaxSource": "/getservicevers/?value=" + QueryString.stage ,"bDestroy" : true ,  "fnServerData" :
                function ( sSource, aoData, fnCallback ) {
                        $.ajax( {
                                 "dataType": 'json',
                                "type": "GET",
                                "url": sSource,
                                "async":false,
                                "success": function (json)
                                {
                                        fnCallback(json);
                                },
                                complete: function() {
                                setTimeout(worker, 5000);
                                }
                        })
                }
                });
        })();

In the UI side I do see AJAX request being made periodically but issue is that the DataTables load perfectly (width/size) first time only in the browser:

Show                                                                                                                                                                                                 Search

XXXXXX                                          XXXXXXXXXXXXX                             XXXXXXXXXXXX                                XXXXXXXXXXXXXX


Showing ...                                                                                                                                                                                        Prev / Next

Second time onwards when AJAX response is received the DataTables just shrinks:

Show                                                                                                                                                                                                 Search

                                                                                  XXXXX    XXXX  XXXXX    XXXX


Showing ...                                                                                                                                                                                        Prev / Next

Note the labels and data are correct but it just that the tables gets shrinked – please help to resolve the issue

Thanks in advance.

====================================UPDATE======================================

I tried the below code:

oTable = $('#example').dataTable();
(function worker() {
                        $.ajax( {
                                "dataType": 'json',
                                "type": "GET",
                                "url": "/getservicevers/?data=" + QueryString.data,
                                "async":false,
                                "success": function (data)
                                {
                                        alert("myObject is " + data.toSource());
                                        alert(data.aaData[0][0]);
                                        oTable.fnClearTable();
                                        for(var i = 0; i < data.length; i++) {
                                            oTable.fnAddData([
                                                data.aaData[i][0],
                                                data.aaData[i][1],
                                                data.aaData[i][2]
                                        ]);
                                }
                                },
                                complete: function() {
                                        oTable.fnDraw();
                                        setTimeout(worker, 5000);
                                }
                });
        })();

The ourput of first two alert statements in success method of AJAX call are:

myObject is ({iTotalRecords:1, iTotalDisplayRecords:1, aaData:[[" data1", " data2", " data3"]]})
data1

The code works fine but in the page I do not see any data in datatables rather:

Show                                                                                                                                                                                                 Search

    XXXXXX                                          XXXXXXXXXXXXX                             XXXXXXXXXXXX                                XXXXXXXXXXXXXX

                                         No data available in table    
    Showing ...                                                                                        

What I need to further on to resolve this and note that I am not see the “Loading …” text when the AJAX request is made. Below is my comeplete code:

<!DOCTYPE html>
<html>

<head>
        <title>My Details</title>
        <meta charset='UTF-8' />
        <link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css" />
        <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
        <script>
        $(document).ready(function() {
        var QueryString = function () {
                                                  var query_string = {};
                                                  var query = window.location.search.substring(1);
                                                  var vars = query.split("&");
                                                  for (var i=0;i<vars.length;i++) {
                                                    var pair = vars[i].split("=");
                                                    if (typeof query_string[pair[0]] === "undefined") {
                                                      query_string[pair[0]] = pair[1];
                                                    } else if (typeof query_string[pair[0]] === "string") {
                                                      var arr = [ query_string[pair[0]], pair[1] ];
                                                      query_string[pair[0]] = arr;
                                                    } else {
                                                      query_string[pair[0]].push(pair[1]);
                                                    }
                                                  }
                                                    return query_string;
                                          } ();
        /* Add the events etc before DataTables hides a column */
        $("thead input").keyup( function () {
                /* Filter on the column (the index) of this element */
                oTable.fnFilter( this.value, oTable.oApi._fnVisibleToColumnIndex(
                        oTable.fnSettings(), $("thead input").index(this) ) );
        } );

        /*
         * Support functions to provide a little bit of 'user friendlyness' to the textboxes
         */
        $("thead input").each( function (i) {
                this.initVal = this.value;
        } );

        $("thead input").focus( function () {
                if ( this.className == "search" )
                {
                        this.className = "";
                        this.value = "";
                }
        } );

        $("thead input").blur( function (i) {
                if ( this.value == "" )
                {
                        this.className = "search";
                        this.value = this.initVal;
                }
        } );
        oTable = $('#example').dataTable();
        (function worker() {
                                $.ajax( {
                                        "dataType": 'json',
                                        "type": "GET",
                                        "url": "/getservicevers/?data=" + QueryString.data,
                                        "async":false,
                                        "success": function (data)
                                        {
                                                alert("myObject is " + data.toSource());
                                                alert(data.aaData[0][0]);
                                                oTable.fnClearTable();
                                                for(var i = 0; i < data.length; i++) {
                                                    oTable.fnAddData([
                                                        data.aaData[i][0],
                                                        data.aaData[i][1],
                                                        data.aaData[i][2]
                                                ]);
                                        }
                                        },
                                        complete: function() {
                                                oTable.fnDraw();
                                                setTimeout(worker, 5000);
                                        }
                        });
                })();
                } );
        </script>
</head>
<body>
        <table id="example">
        <thead>
                <tr>
                        <th>Data1</th>
                        <th>Data2</th>
                        <th>Data3</th>
                </tr>
        </thead>
        <tfoot>
                <tr>
                        <th>Data1</th>
                        <th>Data2</th>
                        <th>Data3</th>
                </tr>
        </tfoot>
        <tbody>
        </tbody>
        </table>
</body>

</html>

The page in accessed from browser by following URL:

http://mybox.com/mon.html?data=test

  • 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-15T07:09:17+00:00Added an answer on June 15, 2026 at 7:09 am

    Your function looks pretty simple, so I’m wondering if this is a graphical glitch caused by the browser. Adding an oTable.fnDraw(); might do the trick.

    Alternatively, if your AJAX call is returning the entire dataset, you can clear the table first with a oTable.fnClearTable(); and change the way you’re adding data into the table by looping over DataTable’s .fnAddData() method.

    $.ajax({
        url: '/getservicevers/?value=" + QueryString.stage',
        type: 'post',
        data: data, // this would be an array
        success: function(data) {
            oTable.fnClearTable();
            // populate the table with data
            for(var i = 0; i < data.length; i++) {
                oTable.fnAddData([
                    data[i].column1,
                    data[i].column2,
                    data[i].column3
                ]);
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The below code doesn't it print the value. function go(x) { alert(x.options.selectedIndex.value); //location=document.menu.student.options[document.menu.student.selectedIndex].value }
In the code below: DbModels.prototype.updateById = function(_collection, id, field, value, callback) { this.getCollection(_collection, function(error,
In the example code below, I'd like to get the return value of the
Hi I have written below code function unique(th){ var obj = {}; for(var i
Using the SQL in the below code: public function saveOrder() { $id = $this->getUserId();
Below code makes form to be submitted without html5 validation... $j(document).on(click, #client_entry_add, function(event){ ajax_submit();});
In the below code how does passing bar as function (n) { return n;
i write below code for sending id to another php file function selectCheckBox(k) {
I have an issue in my JavaScript function. Below is my js code: function
I am using jquery datepicker, please see below code $(document).ready(function() { $(.txtDate).datepicker({ showOn: 'button',

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.