FRIHOST • FORUMS • SEARCH • FAQ • TOS • BLOGS • COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


AJAX





linkview
I have problems try to use html(login)->php1<->js(ajax)<->php2
I don't know how keep data in each session, i have a class in php2 that need to keep data in each call to the ajax.
The class is create in php1, but when is executed php, it does not exists.
Somebody know how keep the data charged in the class ?
rvec
You need cookies to use data in php, java and some other php page. There is no other way to use variables in all those scripts (not as easy as cookies).
http://www.w3schools.com/PHP/php_cookies.asp
badai
session is better and easier.
linkview
I have used sessions.

[1] In php1 and php2, I have used session_start() at the beggining in both scripts, in php1 have declared $_SESSION['var'], but when I tried to use $_SESSION['var'] in php2 it doesn't not exists.

[2] In php1, I have declared:
$task = new Tasks();
Task is a class that is in other php3.
And in php1, I have defined some data in $task.
In php1 and php2, is declared:
include_once('./Tasks.php');
But when php2 try to use that data in $task, it doesn't exists.
rvec
sessions won't work in javascript, so if you want to use those variables there you'll have to make some request back to the server or provide the variable in the source of the javascript.

To use sessions you'll have to put the variables in $_SESSION.
for example for $task -> $_SESSION['task']

If you want to store objects in a sessions you have to make sure you have the class definition loaded before you use the object.

this has to work:
php1:
Code:
<?php
session_start();
$_SESSION['test'] = 'hello world';
?>


php2:
Code:
<?php
session_start();
echo $_SESSION['test'];
?>


oh and I moved the thread to the php forum
badai
[1] something is wrong. you may need to SIMPLIFY your code and post it here

[2] did you pass $task to php2? serialize it and put it in session so that php2 can access it. but first, you need to solve problem [1] before you can do this.

linkview wrote:
I have used sessions.

[1] In php1 and php2, I have used session_start() at the beggining in both scripts, in php1 have declared $_SESSION['var'], but when I tried to use $_SESSION['var'] in php2 it doesn't not exists.

[2] In php1, I have declared:
$task = new Tasks();
Task is a class that is in other php3.
And in php1, I have defined some data in $task.
In php1 and php2, is declared:
include_once('./Tasks.php');
But when php2 try to use that data in $task, it doesn't exists.
linkview
You have reason. Thanks.
I get a solution.

I used serialize in php1 (this code is executed once), and unserialize/serialize in php2 (this code is executed always, because I have a settimeout when I call the ajax in js)

I lost data because I save in $_SESSION['var'] = $task, without serialize
badai
you have no idea what session can store?
Related topics
A use for Ajax?
AJAX tutorial
AJAX based 5 star rating script
AJAX - asynchronous JavaScript and XML
A Ajax tutorial
AJAX?
[TUTORIAL] Ajax para quem só ouviu falar
AJAX web coding
Help making an AJAX messaging system
AJAX
The origin of AJAX
AJAX or servlets?
importing a .txt
AJAX tutorial [2nd part now updated]
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.