0

I have a weird issue with a javascript script that won't run inside my php echo. The script shows in the source page but doesn't run. My file is in a iframe (facebook app), I am using firefox and firebug.

I have a function returning my script as a string, and then I echo this function.

function myFunction($request_token){
    if ($count == 0){
        return "<script>console.log(\"run??\");</script><a href=\"blabla\"></a>";
    }
}

When I look at the source code I see

<script>
    console.log("run??");
</script>
<a href="blabla"></a>

which seems fine, but nothing shows up in the console. I tried to do an alert, won't work either.

Does somebody have an idea?

2
  • Try <script type="text/javascript">. Do you have any other scripts on the page that might throw errors? (scripts are executed in serial, if one throws you're done). Commented Apr 27, 2012 at 20:11
  • I tried to add text/javascript, doesn't work either. I have other scripts + the facebook scripts, but no error shows up in the console Commented Apr 27, 2012 at 20:18

1 Answer 1

1

Have you tried changing <script> to <script type="text/javascript">?

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

3 Comments

Does this help if I say that I load my file with the echo from javascript like that : xmlhttp.open("GET","php/myFile.php?request=init,true); xmlhttp.send(); Then in myFile.php I echo myFunction
@nax_ - So you have a page that uses JavaScript to use AJAX to call a a PHP page to return JavaScript?
Yes I do. Sounds stupid now that you say it but yeah that's how it works. By the way, as you might have guessed xmlhttp is a XMLHttpRequest()

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.