php - jquery function is not sending the value on page load -
i'm sending value from jquery function body, seems jquery not sending value. want fire following jquery function when page loads:
<!doctype html> <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript" src='http://cdn.bitbucket.org/pellepim/jstimezonedetect/downloads/jstz-1.0.4.min.js'></script> <script> $(document).ready(function(){ var tz = jstz.determine(); // determines time zone of browser client jquery('body').load('index.php?session_name='+tz.name()); }); </script> </head> <body>
index.php:
<?php session_start(); if (isset($_get['session_name'])) {$_session['session_name'] = $_get['session_name'];} echo $_session['session_name'];
.............. ..............
php get
gets value url, when use jquery.load
, page has data url not have get
request data, due which, session never set.
if want set session in way, redirect page url want , session set.
so, instead of doing this:
jquery('body').load('index.php?session_name='+tz.name());
redirect page values:
window.location = 'index.php?session_name='+tz.name();
the better way using jquery send request page asynchronously don't have reload page.
the ajax way @ simplest:
$.ajax({ type: "post", url: "index.php", data: { session_name: tz.name() } }).done(function( msg ) { // alert( "session saved: " + msg ); console.log(msg); });
and php:
if (isset($_post['session_name'])) {$_session['session_name'] = $_post['session_name'];} echo $_session['session_name'];
Comments
Post a Comment