Jump to content

[SOLVED] Anyway to use JS objects/variables in a AJAX loaded page?


Balagi

Recommended Posts

So I have an object that I defined in my main page.  I'd like to be able to use that object in a page I load into a DIV with AJAX.  I'm relatively new with JS OOP and Ajax so I don't even know if this is possible.

 

Here's an example:

 

index.php

<script type="text/javascript">
function DB(element, num)
{
    this.element = element;
    this.num      = num;

    this.loadDB = function() {
        // load ajax library - i use Prototype
        new Ajax.Updater('database', 'url/to/database.php');
    }

    this.loadDB();
}

window.onload = function()
{
    DB = new DB('test', 101);
}
</script>

<div id="database">

</div>

 

database.php // this page is loaded into the "database" DIV on index.php

<a href="javascript:void(0);" onclick="javascript:alert(DB.element);">Show value of DB.element</a>

 

Obviously that is just a sample, I got my database.php page loading fine, I'd like to be able to use my previously defined object/variables  from the database.php page.  If this isn't possible, is there a better alternative other than creating a new object with the onclick event and losing my previously defined members?

 

Thank you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.