javascript - Jquery $.post not working as expected -
i'm creating web app using php, jquery, , mongodb , running trouble $.post. have page table each row marked custom button designed in css. use following script index of button , pass php file. gets correct index , posts file fine.
<script> $(".completed").click(function() { var index = $(".completed").index(this); $.post("lock.php", {position: index}); }); </script> lock.php supposed put index session variable , load new page called display_page.php, display_page never gets loaded , no errors displayed in firebug. i've tried posting display_page directly not change anything. here lock.php looks like:
<?php $pos = $_post['position']; session_start(); $_session['index'] = $pos; header('location: display_page.php'); ?> if point in right direction appreciate it.
you need below:-
<script> $(".completed").click(function() { var index = $(".completed").index(this); $.post("lock.php", {position: index},function( data ){ if(data == 'success'){ // check response window.location.href = 'display_page.php'; // if response success redirect page }else{ // alert message } }); }); </script> and in php page:-
<?php session_start(); // first write session start code if(isset($_post['position'])){ // check values coming or not $pos = $_post['position']; $_session['index'] = $pos; echo "success"; // return success ajax }else{ echo "failure"; // return failure ajax } ?>
Comments
Post a Comment