1

I have created a form to upload a a newsletter into the database. I'm using the iFrame method to post the date without the page refresh and I'm displaying a nice jQuery dialog for the loading.

I am now having issues with closing that dialog when the upload is complete. All the tutorials I have read online say that I must just echo out the code like this:

<?php
  echo "<script type='text/javascript>uploadComplete();</script>";
?>

Now the JavaScript does run when I do something stupid to test like just echo out an alert, but when I try and call any function or just go straight to the jQuery to close the dialog it just says that the function is not defined. I can post my code if it is necessary, but it's pretty standard and I didn't think I would need to in this kind of example.

Any help would be appreciated! Thanks in advance.

1
  • Still haven't figured it out.. any other suggestions? Commented Jun 18, 2012 at 10:22

3 Answers 3

5

you forgot ' in the end of 'text/javascript'

echo "<script type='text/javascript'>uploadComplete();</script>";

NB : the type attribute is entirely unnecessary if the script is JavaScript

Sign up to request clarification or add additional context in comments.

1 Comment

Oh that's my bad, but the typo is fixed in my code and it doesn't work. But thanks!
1
using just php

echo '<script type="text/javascript">'
   , 'jsfunction();'
   , '</script>';

escaping from php mode to direct output mode

<?php
// some php stuff
?>
<script type="text/javascript">
    jsFunction();
</script>

1 Comment

I have tried both of these methods but it just wont find the function. And I have double checked the function names that they are correct.
0

I eventually solved this by using the following code:

<?php
  echo "<script type='text/javascript>top.uploadComplete();</script>";
?>

The "top" keyword just solved all of my problems. I hope this helps whoever has the same issue I had!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.