Reputation: 13
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?
Upvotes: 0
Views: 1067
Reputation: 30002
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 } ?>
Upvotes: 1
Reputation: 449485
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; ?>
Upvotes: 4