Jump to content


AJAX Request Help


2 replies to this topic

#1 Pooch

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 03 July 2007 - 11:46 PM

Hi,

I have encountered a problem when I attempt to use AJAX to send and write JavaScript to a web page.

My web page has a button on it that when clicked runs an AJAX request and returns/writes JavaScript from a file to the web page (the page being viewed). Though once the JavaScript is imported it does not run. I believe this is because the browser only reads the page once and after the new JavaScript added to the page is only picked up as text (Does this seem right?). However, the Javascript does run if I specify an event.

I was wondering if an event exists that would run the JavaScript once it was added to the page? Are there any other ways of doing this?

Any advice is greatly appreciated.
Thanks.

Edited by Pooch, 03 July 2007 - 11:47 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 04 July 2007 - 12:01 AM

AJAX is javascript. It is a method of use, not a language. Using JavaScript to "write" JavaScript to the page would naturally not run it, as you have already assumed.

There are two ways around this. Well, technically one, but still 2.

1. Use the eval() function.
2. Read up on JSON. It is the same as AJAX, but rather than having the intended use of returning XML, it returns JavaScript, usually in a kinda funky syntax (i say funky because i first found out about it through JSON. Till then i had no clue it existed. Regular JS still works the same though). Anyway, you would again have to use the eval function for this... which is why i said theres technically only one way.

#3 Pooch

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 05 July 2007 - 10:39 PM

Thanks for the help. I was able to use the eval() function to run the JavaScript returned.

Thanks again for the response.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users