Ruven JR. Maerson
Ruven JR. Maerson

Reputation: 309

Why is the object always empty?

i have a little problem with my Ajax calls. Maybe i do not have the right approach here or i did not understand it correctly.

Here is what i do: i create a new object once and set a value with the function set_value for a variable defined in the __constructor in createobj.php

$obj->set_value(10);

The object is created in class_obj.php. and the value is 10.

Then i make an ajaxcall with jquery and json:

$jq.getJSON(ajaxcall.php? + options, function(data) {

But when i call the obj in ajaxcall.php again it is empty? I do not understand why, so i appreciate any tipps, tutorials ebooks and your help for better understanding.

How can i achieve it, that i can access the same object created in createobj.php in ajaxcall.php with all values, setting new ones etc.? So a "global" object. Or do i have to send the obj with the ajaxcall?

Thank you for bringing light into the dark ;)

Upvotes: 0

Views: 261

Answers (1)

Nick
Nick

Reputation: 6346

Sounds like you're expecting the value to stay as it was when you execute another script (the AJAX script), which won't work, they will act as completely different scripts, so no information will be passed between them.

You'd either have to set the value to a SESSION, or save it in some way (e.g. to a database) and then "load" the values from an ID set in a SESSION variable.

Upvotes: 1

Related Questions