Ahmed Syed
Ahmed Syed

Reputation: 1189

How to refresh an element using AJAX?

I have an element for ex. <div>. and in that I have fetched dynamic contents from database, I am already performing some database operation using AJAX and I am able to load some part of my page from other php file, but on the same page I want my other div to be repopulate its data from database.

This is my manage_your_listing.php

<div class="col-sm-12 pd">
  <ul class="nav nav-tabs notificationtabs">
    <li class="active"><a href="#live_on_site" data-toggle="tab">Live On Site</a></li>
    <li><a href="#pendding_review" data-toggle="tab">Pending Review</a></li>
    <li><a href="#pause" data-toggle="tab">Pause</a></li>
  </ul>
</div>
<div class="tab-content">
  <div class="tab-pane fade active in" id="live_on_site" >
    <?php
        include'manage_order/live_on_site.php';
    ?>
  </div><!-- End tab1-->                    
  <div class="tab-pane fade" id="pause" >
    <?php
        include'manage_order/pause_order.php';
    ?>  
  </div><!-- End tab2 -->
</div><!-- End tab-content -->

this is my live_on_site.php's AJAX function

function ConfirmPause(prod_id){
  $.ajax({
    type: "get",
    url: "seller/manage_order/live_on_site_pause.php?prod_id="+prod_id.id,
    cache: false,
    dataType: "html",
    asyc: false,
    success: function (data) {
      $("div#live_prod").html(data);
    }
  });
}

so finally my live_on_site.php's live_prod div is being repopulated with the contents of live_on_site_pause.php

but what I want is, there is div in pause_order.php which is accessible in every php file specified here, and that div is being populated with some database content by using select statement, and I want it just to refresh, Is it possible? or do I need to create a new php file and call it using ajax?

Upvotes: 2

Views: 1843

Answers (2)

user4813187
user4813187

Reputation:

you cant just refresh an element with ajax, you can either process something in ajax or in other file and replace it with old contents using ajax.

Upvotes: 1

Ahmed Syed
Ahmed Syed

Reputation: 1189

I solved it by using nested ajax function. I wanted to refresh one div after processing of some database update using ajax, But later I found that there is no way ajax can refresh div, it just copies some data from source position and paste it into specified position. So while success of previous ajax function I typed one more ajax function which worked for me.

function ConfirmPause(prod_id)
{
    if (confirm("Pause Product?"))
    {
        $.ajax({
            type: "get",
            url: "seller/manage_order/live_on_site_pause.php?prod_id=" + prod_id.id,
            cache: false,
            dataType: "html",
            asyc: false,
            success: function (data) {
                $("div#live_prod").html(data);

                //nested ajax to change pause products tab real time the moment user pauses a product it will get removed from live tab and will be added to pause products tab
                $.ajax({
                    type: "get",
                    url: "seller/manage_order/pause_order_resume.php",
                    cache: false,
                    dataType: "html",
                    asyc: false,
                    success: function (data) {
                        $("div#pause_prod").html(data);
                    }
                });
            }
        });
    }
}

Upvotes: 3

Related Questions