Say for example I have a page with 100 includes.

How would I reload just one of them?

Say I ran an ajax script that did certain tasks on the server side, but I didn't want to display the information by setting it in the ajax script - Instead I want to just reload the include so that it will show the new information.

If this is not possible, is it possible to reload a table without refreshing the entire page?


6 Years
Discussion Span
Last Post by diafol

Ok, thanks... Sorry I should've been more specific.

Ok. Basically this is how it goes:

I have a php file (HOME.php) that has 2 includes and the ajax calls on it.
1. (LOGGED IN.php) that has a session set to null on it.
2. (CHECK LOGIN DETAILS.php) After the user logs in, the ajax call goes to this page where the session is set to the users email address.

Now my objective is to refresh the (LOGGED IN.php) include without refreshing the whole page, so that it displays the session without me manually using xmlresponse, where I would have to set the css again, etc.



You should return a string with the HTML and/or PHP actions and then, show it on the included logged in.php part of your home.php... do you understand ?


I was avoiding doing it this way though because of certain implications... I'd much rather prefer to refresh/reload the include so the session variable is set to the users email instead of null...


I do, but then I use echo $_SESSION to display it on a separate include. So it's initially set to null, but after logging in, it should refresh the include so that it's not null anymore, and it displays what it's currently set to after logging in.


This sounds a bit overcomplicated. Why not have the js refresh the area of the screen? You can pass an array of data from the php include (as an array - json is great for this) back to the js. JS then updates the relevant areas.


Again, the problem will come in when I need to read the data - because the included php file's reference to the session wont be submitted yet... Or will it?

Basically, if I had to draw it out, it would be like this:

Home.php -> 2 includes which are:
LoggedIn.php -> Session = null
Login.php -> Run ajax, set session to users email address

After running ajax and setting session to users email address, I need to refresh/reload LoggedIn.php so that where the session = null, now becomes the users login email address.

I hope that makes more sense. Sorry for the up and down annoyance.


No, it's as I thought.

If your loggedin.php file is enclosed within say a div tag with an 'id' set to 'log', you can set the contents of the div to anything you want with js after it receives the data from the php script.

<div id="log">
<?php include('includes/loggedin.php');?>

<...some other stuff to cause ajax call to a js script login(), e.g. form button...>

The js then can do something like this (I'm using jQuery here - useful for Ajax):

function login(){
	var user = $('#username').val();
	var pw = $('#pw').val();

	$.post("includes/login.php", { "user": user, "pw": pw },
            if(data.resultvalue == "success"){        
              $("login").html("<p>Your login details are incorrect!</p>");

This example is a little raw, but I expect you get the idea.
The login.php can include the loggedin.php file and return the contents as emailaddr if the login details are valid. I use json when I want to return an array of data. It's simple and tends to 'just work'.


Thanks.. Ya I really have to start getting into jQuery, it seems to be the "in thing" that everyones using these days.



$("login").html("<p>Your login details are incorrect!</p>");

should have been

$("log").html("<p>Your login details are incorrect!</p>");
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.