Balagi Posted February 13, 2007 Share Posted February 13, 2007 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 https://forums.phpfreaks.com/topic/38374-solved-anyway-to-use-js-objectsvariables-in-a-ajax-loaded-page/ Share on other sites More sharing options...
Balagi Posted February 14, 2007 Author Share Posted February 14, 2007 Nevermind, I got what I wanted to work. It was a combination of defining the object in the onload function and a never ending javascript loop that I completely overlooked. Link to comment https://forums.phpfreaks.com/topic/38374-solved-anyway-to-use-js-objectsvariables-in-a-ajax-loaded-page/#findComment-184711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.