Sylvite
Sylvite

Reputation: 39

Refresh part of page with PHP/AJAX

Yes, I know that you can refresh the page every number of seconds with AJAX but I want to be able to do this with PHP. Basically running a PHP script where I can say a command which then triggers AJAX to refresh the page.

I could not find this anywhere, no guide or post on here. Please lead me into the right direction. Thank you.

I am not asking you to write code, I am asking for you to tell me a method to do this.

Upvotes: 1

Views: 62

Answers (1)

Artem Ilchenko
Artem Ilchenko

Reputation: 1035

You can't reload page that sending AJAX request.

If you sending request by JavaScript you can reload page only by JavaScript.

If you send Location header from PHP you get redirect for your XmlHttpRequest object. So use JavaScript for this.

For example you can do AJAX request to your server and write something like this in callback:

function(response) {
    var el = document.getElementById('el');
    el.innerHTML = response;
}

Upvotes: 1

Related Questions