1,105,384 Community Members

PHP Reload Include

Member Avatar
AshtonHogan
Posting Whiz in Training
209 posts since Jul 2009
Reputation Points: -3 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

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?

Thanks,
Ashton.

Member Avatar
P0lT10n
Posting Whiz in Training
237 posts since Apr 2010
Reputation Points: 3 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 0 [?]
 
0
 

with ajax you only need to pass data and it will responde you what you need...

Member Avatar
AshtonHogan
Posting Whiz in Training
209 posts since Jul 2009
Reputation Points: -3 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Thanks,
Ashton.

Member Avatar
P0lT10n
Posting Whiz in Training
237 posts since Apr 2010
Reputation Points: 3 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 0 [?]
 
0
 

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 ?

Member Avatar
AshtonHogan
Posting Whiz in Training
209 posts since Jul 2009
Reputation Points: -3 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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...

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

WHy don't you set the session variable within the login function/include?

Member Avatar
AshtonHogan
Posting Whiz in Training
209 posts since Jul 2009
Reputation Points: -3 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

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.

Member Avatar
AshtonHogan
Posting Whiz in Training
209 posts since Jul 2009
Reputation Points: -3 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

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');?>
</div>

<...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 },
   	  function(data){
            if(data.resultvalue == "success"){        
	      $("#login").html(data.emailaddr);
            }else{
              $("login").html("<p>Your login details are incorrect!</p>");
            }
          },
        "json");
}

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'.

Member Avatar
AshtonHogan
Posting Whiz in Training
209 posts since Jul 2009
Reputation Points: -3 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
diafol
Where are my eyes?
12,977 posts since Oct 2006
Reputation Points: 1,821 [?]
Q&As Helped to Solve: 1,848 [?]
Skill Endorsements: 92 [?]
Moderator
Featured
Sponsor
 
0
 

SORRY

$("#login").html(data.emailaddr);
 }else{
$("login").html("<p>Your login details are incorrect!</p>");

should have been

$("#log").html(data.emailaddr);
 }else{
$("log").html("<p>Your login details are incorrect!</p>");
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: