doflamingo doflamingo - 4 years ago 131
Ajax Question

jquery ajax - why .load() cannot load self page?

I try to refresh some

div
in my page with ajax load by using
.load()
but not 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");
});

Answer Source

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download