php - jquery .post not working -
i working following code:
action.php
<?php $_session['passtext'] = $_post['passtext']; ?> index.php
<script type="text/javascript"> $(function(){ $("#clickable").click(function() { $.post("action.php", { passtext: "hello" } ); alert('refresh page see session text'); }); }); </script> <a href="javascript:void(0);" id="clickable">click me set session text</a> <?php if(isset($_session['passtext'])) echo $_session['passtext']; ?> when click link, alert, seems action.php isn't running @ -- because refresh page , see no echo of $_session['passtext'] (it isn't being set)
there no errors in error console either
what missing?
you need add line @ beginning of files before deal sessions:
session_start(); from php docs:
session_start() creates session or resumes current 1 based on session identifier passed via or post request, or passed via cookie.
Comments
Post a Comment