By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,481 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,481 IT Pros & Developers. It's quick & easy.

Ajax Page Problem

P: 384
I have a page which loads the below code on a button click, if i access the page(ajax-150-null/) via its direct link the javascript function 'radio' works fine but if i click the button on the webpage the radio function doesn't seem to work?

N.B. - The forward slashes are there because its in a PHP function.
Expand|Select|Wrap|Line Numbers
  1. <div id="radio_wrapper">
  2.       <form>
  3.       <script src="../sys/js/radio.js" type="text/javascript">
  4.         radio(\'width\',\'450\',\'height\',\'120\',\'data\',\'\',\'type\',\'application/x-shockwave-flash\',\'src\',\'\');
  5.       </script>
  6.       <noscript>
  7.         <object width="450" height="120" data="" type="application/x-shockwave-flash">
  8.           <param name="src" value="" />
  9.         </object>
  10.       </noscript>
  11.       <div id="radio_refresh_button_wrapper">
  12.         <input type="submit" value="Refresh Radio" onclick="getcontent(\'ajax-150-null/\',\'radio_wrapper\'); return false;"/>
  13.       </div>
  14.       </form>
  15.       </div>
Jun 11 '09 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 5,390
when loading something through ajax then the inculded javascript is not evaluated when you just add the content ... you would need to eval() the script part explicitly and then call the function when the call is successfully ready.

kind regards
Jun 12 '09 #2

P: 384
I understand what your saying, not sure how i go about resolving the issue though?
Jun 15 '09 #3

Expert Mod 15k+
P: 16,027
Separate the JavaScript from the HTML and either eval or add to the head (of the calling/parent page) via a script tag, e.g.
Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. script.type= "text/javascript";
  3. script.src = "src/to/js/file.js"
  4. document.getElementsByTagName("head")[0].appendChild(script);
I notice that you're mixing src and actual code together too. Separate that into:
Expand|Select|Wrap|Line Numbers
  1. <script src="../sys/js/radio.js" type="text/javascript"></script>
  2. <script type="text/javascript">
  3.     radio(\'width\',\'450\',\'height\',\'120\',\'data\',\'\',\'type\',\'application/x-shockwave-flash\',\'src\',\'\');
  4. </script>
though in this case, it'd be better to put the radio() call in the same file or another file which you can reference easily.
Jun 16 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.