php - $_SESSION['var'] won't set with ajax -
i'm having strange problem. i'm trying set session vars , , won't set through ajax call.
here code
html
<form id="sjcc_payment" onsubmit="return concatexp();" action="https:www.url.com" method="post"> <table width="100%"> <tr> <td style="font-family:tahoma,geneva,sans-serif;color:#888888">name</td> </tr> <tr> <td><input type="text" id="first_name" name="first_name" ></td> </tr> <tr> <tr> <td style="font-family:tahoma,geneva,sans-serif;color:#888888">email</td> </tr> <tr> <td><input type="text" id="email" name="email" ></td> </tr> <tr> <td style="font-family:tahoma,geneva,sans-serif;color:#888888">payment for:</td> </tr> <tr> <td><input type="text" id="payment_for" name="payment_for" ></td> </tr> <tr> <td style="font-family:tahoma,geneva,sans-serif;color:#888888">payment amount: </td> </tr> <tr> <td><input type="text" id="total" name="total" ></td> </tr> </table> <h2 style="color:#555">please enter payment information</h2> <table width="300" style="float:left"> <td > card type </td> </tr> <tr> <td > <input type="radio" name="cardtype" value="visa" checked> <img width='80px' src='/media/media/images/cardvisa.png' /><br> <input type="radio" name="cardtype" value="mc"> <img width='80px' src='/media/media/images/cardmc.png' /> </td> </tr> <tr> <tr> <td > credit card # </td> </tr> <tr> <td > <input type="text" placeholder="cc #" name="card" id="card" value=""> </td> </tr> <tr> <td width="20%"> exp. </td> </tr> <tr> <td> <input type="text" style="width:60px;float:left;" placeholder="mm" name="expmonth" maxlength="2" id="expmonth" value=""> <div style="float:left;padding:10px 5px 0px 5px; font-size:18px;"> / </div> <input type="text" style="width:60px;float:left;" placeholder="yy" name="expyear" maxlength="2" id="expyear" value=""> </td> </tr> <tr> <td> cvv </td> </tr> <tr> <td> <input type="text" placeholder="cvv" style="width:70px;float:left;" name="cvv" id="cvv" value=""> </td> </tr> <tr height="55px"> <td valign="bottom"> <a class='pay-button'>submit payment</a> </td> </tr> <tr> <td > <p> </p> </td> </tr> </table> </form>
my ajax call
(function ($) { $(document).on ('click', '.pay-button', function() { var name = document.getelementbyid("first_name").value; var email = document.getelementbyid("email").value; var paymentfor = document.getelementbyid("payment_for").value; var paymentamount = document.getelementbyid("total").value; console.log (email); //is correct email. $.ajax({ type:'post', url: '/setsession.php', data: { name:name, email:email, paymentfor:paymentfor, paymentamount:paymentamount}, success: function(data) { console.log(data); //is correct $email. } }); }); }(jquery));
in setsession.php
<?php //initialize session session_start(); $date = date('ymdhis'); $name = $_post['name']; $email = $_post['email']; $paymentfor = $_post['paymentfor']; $paymentamount = $_post['paymentamount']; $_session['invoice'] = $date; $_session['ec_name'] = $name; $_session['email'] = $email; $_session['payment_for'] = $paymentfor; $_session['payment_amount'] = $paymentamount; echo $email; ?>
now when reload page.. session not set.
Comments
Post a Comment