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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:07:09+00:00 2026-06-11T15:07:09+00:00

I had a long question along with my complete code but now it is

  • 0

I had a long question along with my complete code but now it is shorter one.

  function showRecord(tbl) {
    myDataTable.fnDestroy();
    $.ajax(
    {
        data: "tableName=" + tbl,
        url: "showTable.php",
        dataType: "html",
        success: function (data) { $("#example").html(data); }
    });
    alert('I get desired output as long as I do not comment/remove this alert');
    myDataTable = $('#example').dataTable();
}

BUT if i just comment the alert I do not get data from database

If I do not use $('#example').dataTable(); (a jquery plugin for pagination from datatables.net ) then code works fine without alert.

function showRecord(tbl) {
    //myDataTable.fnDestroy();
    $.ajax(
    {
        data: "tableName=" + tbl,
        url: "showTable.php",
        dataType: "html",
        success: function (data) { $("#example").html(data); }
    });
  //alert('I get desired output as long as I do not comment/remove this alert');
  //myDataTable = $('#example').dataTable();
}

I need to know why alert is necessary in first sample of code. If it causes delay, why delay is necessary here and how to achieve this without using alert

  • 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-11T15:07:10+00:00Added an answer on June 11, 2026 at 3:07 pm

    Ajax calls are asynchronous. In the first block of code (if there is no alert) ajax call get executed and then immediately after that (before server responds) this line executes:

    myDataTable = $('#example').dataTable();
    

    and since server did not return result yet $('#example') is empty. You can put it it like this:

    function showRecord(tbl) {
        myDataTable.fnDestroy();
        $.ajax(
        {
            data: "tableName=" + tbl,
            url: "showTable.php",
            dataType: "html",
            success: function (data) {
                $("#example").html(data);
                myDataTable = $('#example').dataTable();
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been a long time browser here, but never have had a question that
In another question I had the problem to port the code: unsigned long stack[]
I've been using SO for a long time but finally had a question I
I have had a long problem with this code. I have posted this question
I had that question in mind for a long time. Theoretically, jQuery core function
One thing with which I have long had problems, within the CakePHP framework, is
Had a good read through similar topics but I can't quite a) find one
I had another question about this issue, but I didn't ask properly, so here
I had a long detailed question about how to get a specific calendar's event
This is quite a long introduction to a simple question, but otherwise there will

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.