[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 842
  • Last Modified:

Javascript/AJAX Eval(), How to load JAVASCRIPT after AJAX is called!

I am using the following snippet here:

http://www.developersnippets.com/2009/05/20/evaluate-scripts-while-working-on-ajax-requests/

Basically, for example, I have a index.php and a page that loads with ajax. we'll call that one ajaxpage.php . When theres no javascript in that page, its fine, But if I do something like..

HELLO THERE MATEY!<br>
<script language="JavaScript">
document.write("hello!<br>"):
</script>
OTHER STUFF AFTERWARDS

what ends up happening is everything but  document.write("hello!"): is called. so the page thats left is only

"hello!
"

But missing the any other additional HTML/PHP. But If I load up  ajaxpage.php. It will display properly, aka:

"HELLO THERE MATEY!
hello!
OTHER STUFF AFTERWARDS"

Basiclly, I'm trying to figure out how ajax can do this properly.

I've also tried to use a countdown script located here: http://www.dynamicdrive.com/dynamicindex6/dhtmlcount.htm

Which again works great if you load the ajaxpage.php directly, but if you do the index.php page that loads the ajaxpage.php file, the result is BLANK.. So I'm guessing there is an issue using EVAL here .. Any suggestions? Thanks!
0
Valleriani
Asked:
Valleriani
1 Solution
 
ZylochCommented:
What happens when you load the first ajaxpage.php without adding the snippet from the link? I am not surprised that you only get "hello!" with it, because calling document.write() anytime after the page has loaded overwrites what is originally on the page.

Also, please consider if there is any way to avoid loading JavaScript through AJAX. Ask yourself whether you really need AJAX for this, or if an iframe would do. This is because I would not be surprised if you ran into some very confusing problems by trying to emulate JavaScript parsing using eval().
0
 
VallerianiAuthor Commented:
Hm Thanks.

The issue is I need a REAL countdown timer on a page that updates every 60 seconds. it must countdown from 60 to 0 basiclly. However, most of the 'update content' is in the 'ajaxpage.php file'.. Not sure what I can do :\ It has to be 'real updates' without a refresh style update, which is quote a pain to do (For work, boss wanted 'live numbers' that don't refresh the whole page so it doesn't scroll away etc)

When I load it without adding the snippit, it works fine and dandy!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now