0

I have a file javascript.php which is inserted into my PHP File like this

$data = array(...Some parameters...);
echo '<script src="path/to/file/javascript.php?'.http_build_query($data).'" type="text/javascript"></script>'."\n";

The javascript.php file looks like this:

<?php header('Content-Type: text/javascript'); ?>

$(window).load(function() {
    alert('Loaded: <? $_GET['someparameter'] ?>');
});

But it only alerts Loaded: nothing with the $_GET.

What did I do wrong, how can I get the Parameters of the URI?

3
  • escape, escape, escape Commented Feb 4, 2014 at 10:17
  • 2
    <?=$_GET['someparameter'] ?> or <? echo $_GET['someparameter'] ?> Commented Feb 4, 2014 at 10:17
  • $_GET is aserver side variable, that you`re trying to catch on a brosser side. parse it to javascript Commented Feb 4, 2014 at 10:20

2 Answers 2

4

instead using:

alert('Loaded: <? $_GET['someparameter'] ?>');

use like this:

alert('Loaded: <?php echo $_GET['someparameter'] ?>'); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, totally missed that. Sometimes you just get blind of all the code
1

You've missed the =.

<?=$_GET['someparameter'] ?>

2 Comments

Does the = stand for echo?
Its alternative to <?php echo.

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.