0

Is there anyway to check a PHP $_GET variable in jQuery?

Here is what i mean:

var refreshId = setInterval(function()
{
$('.updatearea').load('main.php<?=$url?> .updatearea');
}, 5000);

I only wanna execute the code above IF (isset($_GET['phpvariable'])

Is that possible?

2 Answers 2

4

Is that possible?

Yes, but the more elegant way might be to use PHP to decide whether the code should be output in the first place:

 <? if (isset($_GET['phpvariable']): ?>

 var refreshId = setInterval(function()
 {
  $('.updatearea').load('main.php<?=$url?> .updatearea');
 }, 5000);

 <? endif; ?>
Sign up to request clarification or add additional context in comments.

Comments

1

Why do it in JavaScript and not in PHP?

<?php if(isset($_GET['phpvariable'])){ ?>
var refreshId = setInterval(function()
{
$('.updatearea').load('main.php<?=$url?> .updatearea');
}, 5000);
<?php } ?>

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.