HDRebel88 Posted July 28, 2013 Share Posted July 28, 2013 (edited) I'm trying to run a check via jQuery/AJAX to see if the user loading the page has Javascript turned on... if they do I need to reload the page, after setting a session variable in PHP so I can activate javascript based controls that I need to have turned off if the user doesn't have javascript turned on. The controls turned off is the default... Here's my AJAX call: $(document).ready(function(){ $.ajax({ url: "jscheck.php", context: document.body, success: function(data){ if (data=='yes') { window.location = '/films/'+filmTitle; } else { } }}); }); Here's my php: <?php session_start(); $_SESSION['jsCheck']="yes"; echo $_SESSION['jsCheck']; ?> This works but the page just keeps looping and looping. Edited July 28, 2013 by HDRebel88 Quote Link to comment https://forums.phpfreaks.com/topic/280608-running-jquery-ajax-only-once/ Share on other sites More sharing options...
nogray Posted July 29, 2013 Share Posted July 29, 2013 A better approach would be to load the page as if javascript was turned off and add the controls using javascript. (http://en.wikipedia.org/wiki/Progressive_Enhancement) The reason your page keeps loading is because your success function basically keeps redirecting the page. You can use a php if statement to check if the session has been set or not. If not, print out the ajax request. Also, you can also simply set the default to show the javascript controls by default (since most people have javascript support) and use the noscript and meta refresh tags to set the session to no javascript controls (you still would need to check if the session is set before printing out the noscript tag). Quote Link to comment https://forums.phpfreaks.com/topic/280608-running-jquery-ajax-only-once/#findComment-1442600 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.