Member Avatar for feoperro

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 for P0lT10n

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

Member Avatar for feoperro

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 for P0lT10n

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 for feoperro

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 for diafol

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

Member Avatar for feoperro

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 for diafol

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 for feoperro

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 for diafol

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 for feoperro

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

Member Avatar for diafol

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>");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.