My First Ajax Program | jQuery Ajax calls in your WordPress blog


<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js”></script&gt;
<script type=”text/javascript”>
    $(document).ready(function(){
    $.ajaxSetup({cache:false});
    $(“#recordtab li a”).click(function(){
        var post_id = $(this).attr(“rel”)
        $(“#recordcontent”).html(“loading…”);
        $(“#recordcontent”).load(“http://localhost/indianic/triqui-ajax?id=&#8221; + post_id);
        return false;
    });
});
</script>
<ul id=”recordtab”>
<?php
    global $wpdb;
    $table_name = $wpdb->prefix . “testimonials”;
    $sqls = “SELECT DISTINCT company FROM $table_name Order by company”;
    $tstlist = $wpdb->get_results($sqls);
    foreach ($tstlist as $tstlist2) {
        echo ‘<li><a href=”#” rel=”‘ . $tstlist2->company . ‘”>’ . $tstlist2->company . ‘</a></li>’;
        echo “<br>”;
    }
 ?>
 </ul>
<div id=”recordcontent”>
   
</div>

External File : triqui-ajax

Ex : http://localhost/indianic/triqui-ajax

<div class=”record”>
<?php
    $recordid = $_GET[‘id’];
 ?>
<?php
    global $wpdb;
    $table_name = $wpdb->prefix . “testimonials”;
    $sqls = “SELECT * FROM $table_name where company = ‘$recordid’ “;
    $tstlist = $wpdb->get_results($sqls);
    foreach ($tstlist as $tstlist2) {
        echo $tstlist2->testid;
        echo $tstlist2->text_short ;
        echo $tstlist2->text_full ;
        echo $tstlist2->clientname ;
        echo $tstlist2->company;
        echo $tstlist2->homepage;
        echo “<br>”;
    }
 ?>
 </div>

Advertisements