tags:

views:

302

answers:

1

Hi,

I am using an JavaScript (and AJAX) to dynamically load a PHP page into a DIV, (when a hyperlink is clicked the div gets code from an external file loaded into it without the page refrshing).

The problem i am having is that when i use PHPLiveX (an AJAX framework for PHP) within the DIV it does not work, however when i load the page seperately it does. PHPLiveX creates JavaScript at runtime and puts it within the page body. This may be why the page does not work but i am not sure.

Sorry if this is badly explained. Thanks.

A: 

If I understand (and assume) correctly:

  • You are inserting content into a page using innerHTML
  • The content includes JavaScript, which isn't being recognised

This is one of the limitations of innerHTML. I'd rewrite it so the scripting was implemented differently. (The specifics would depend on what the script did in the first place)

David Dorward
Thanks for the reply. Yes, you are right. I guess i will just have to rewrite it. Any ideas on a better way to load content without refreshing the page but allowing the javascript to run? I would preferably like to avoid iframes.
As I said, it depends on the specifics of what the script does. (It could be a case that you are just reinventing frames using JavaScript, which is worse then using real frames - but you've provided so little detail that it is impossible to say for sure)
David Dorward
Sorry, the pages are being used as part of a Facebook application (a game). What i am trying to do is insert data into a database without refreshing the page. Similarly i am trying to change the content of the div without refreshing the page. I guess i will just use iframes until a better solution arrives.
One final update. I liked the InnerHtml script so i left it in and just moved the PHPLiveX code into the index.php instead of each individual page. This may not be the ideal solution but it does the job. Thanks for the help David.
Another change: i decided to change the loading part to jQuery (http://docs.jquery.com/Ajax/load). This allows me to put scripts in each individual page.