2

alright so here is my problem i have got a jquery function and a php script

jquery function:

function set_session(para){
     //Send Ajax request 
     var dataString = 'waarde='+ para ;
   jQuery.ajax({
    url: '../js/set_session_side.php', 
    type: 'POST',
    data: dataString,
    cache: false,
    success: function(data, textStatus, xhr) {
        console.log(data); // do with data e.g success message
    },
    error: function(xhr, textStatus, errorThrown) {
        console.log(textStatus.reponseText);
    }
});}

set_session.php:

<?php 
$_SESSION['side'] = $_POST['waarde'];
 ?>

when i run the jquery function there is a succes, but no data, and my php script is not working/ or not being triggerd, because $_SESSION['side'] is not changing.

any help would be appriciated. thanks in advance

4
  • you should use session_start(); at the top of your php script in order to REuse the session. it just a single thing that is wrong, but there may be a little bit more Commented Mar 16, 2014 at 12:39
  • Oke noob mistake i forgot that i should also start a session in set_session.php because it won't run on the same page as the jquery code. <?php session_start(); $_SESSION['side'] = $_POST['waarde']; ?> fixed it Commented Mar 16, 2014 at 12:40
  • you need to start the session first in php. Commented Mar 16, 2014 at 12:46
  • Are you getting the data on $_POST['waarde']? Commented Mar 16, 2014 at 12:51

1 Answer 1

1
  1. First make sure your requesting script is correct.
  2. add sesstion_start() at the beginning of your set_session.php ( i believe your problem is here);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.