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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:41:18+00:00 2026-05-27T06:41:18+00:00

I want to initialize a jquery function when the ajax request is done and

  • 0

I want to initialize a jquery function when the ajax request is done and got response successfuly. Because am trying to get a table as ajax response and sort it out as a grid using data table jquery plugin for girds

The function initializes this way

$(document).ready(function() {
$('#data_grid').dataTable();
    } );

Function which will be triggered on success of the ajax response

function showgValid()
{
    if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
    {document.getElementById('loadingImg').style.display='none';
    data =xmlHttp.responseText;

    document.getElementById("genPay").innerHTML=data;

    }
}

On success of the ajax response, the innerHTML of genPay div will become the responsetext,
the response text will be a table with an id data_table.

The ajax request will be sent and got from the file below:

 <?

require_once '../config.php';

$db = $_GET['db'];

$table = $_GET['table'];

$_SESSION['table']=$table; 

 ?>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <style type="text/css" title="currentStyle">
            @import "demo_page.css";
            @import "demo_table.css";
        </style>

        <script type="text/javascript" language="javascript" src="jquery.js"></script>
        <script type="text/javascript" language="javascript" src="jquery.dataTables.js"></script>
        <script language ="javascript" src="js/abtAjax.js" type="text/javascript"></script>
        <script type="text/javascript" src="js/ajax.js"></script>
        <script type="text/javascript" charset="utf-8">
            $(document).ready(function() {
                $('#data_grid').dataTable();
            } );



        </script>
    </head>
    <body id="dt_example">
        <div id="container">






<table cellpadding="0" cellspacing="0" border="0" class="display"  id="data_grid">

    <thead><?
    if ( $line == 0 )
    {

?>
<tr>
    <?php
     $sql=mysql_query("show columns from $table");
     while($res = mysql_fetch_row($sql))
     {
     echo "<th bgcolor='".( ( $line % 2 ) ==0 ? '#efefef' : '#ffffff'  )."'>$res[0]</td>";

     }
    ?>
</tr>
<?
}
$line++;
?>
</thead>
    <tbody>
        <?php
$result = mysql_query( "select * from $table" ); 
$num_rows = mysql_num_rows($result); 

while ($get_info = mysql_fetch_object($result)){ 
print "<tr>";
foreach ($get_info as $field) 
print "<td>$field</td>"; 
print "</tr>"; 
} 

?>
    </tbody>
<?
print "</table>"; 
?>


            <div class="spacer"></div>






        </div>
    </body>
</html>

The problem is that am not getting the grid am expecting. I think the function is not initializing on success of the ajax request. please correct me to get rid of this problem

  • 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-27T06:41:18+00:00Added an answer on May 27, 2026 at 6:41 am

    $(document).ready() will not fire after your ajax call. It only fires when the page is first loaded. If you want $('#data_grid').dataTable(); called after your ajax call, then just call it from the success handler of the ajax call.

    function showgValid()
    {
        if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
        {
            document.getElementById('loadingImg').style.display='none';
            data =xmlHttp.responseText;
    
            document.getElementById("genPay").innerHTML=data;
    
            // ADD THIS LINE to your ajax success handler
            $('#data_grid').dataTable();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Often times I come across situations where I want to execute a jQuery function
I am trying to modify this JQuery Countdown plugin to initialize itself when it
I want to initialize a struct element, split in declaration and initialization. This is
I want to initialize a static collection within my C# class - something like
I want to initialize an array and then initialize a pointer to that array.
In C#, I want to initialize a string value with an empty string. How
I want to use CodeDOM to both declare and initialize my static field in
I need to initialize few objects, it can take a while so I want
I want to create an object, let's say a Pie. class Pie def initialize(name,
I'm creating a basic widget for toggling elements visibility. To initialize, the function looks

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.