1

I tried to refresh some div in my page with ajax load by using .load() but didn't work. I have to create new file page that use php to echo my div again. So Question is Do I have to create new file for echo that div, if I just want to refresh some div in my page?

$("button").click(function(){
    $("#div1").load("currentpage.php");
});

above is not work.

I have to use below code.

$("button").click(function(){
        $("#div1").load("otherpage.php");
    });
Lahiru
  • 1,428
  • 13
  • 17
doflamingo
  • 567
  • 5
  • 23

1 Answers1

1

Use Ajax for this.

Build a function that will fetch the current page via ajax, but not the whole page, just the div in question from the server. The data will then (again via jQuery) be put inside the same div in question and replace old content with new one.

Relevant function:

http://api.jquery.com/load/

eg

$('#thisdiv').load(document.URL +  ' #thisdiv');

Note, load automatically replaces content. Be sure to include a space before the hastag.

Reference link : Refresh Part of Page (div)

Community
  • 1
  • 1
Sujal Patel
  • 2,444
  • 1
  • 19
  • 38