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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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