title: Session Variable with ajax seems empty
body: <p>I have a piece of code which is giving me trouble.<br>
  I am trying to get order values from a php class function :</p>
  
  <pre><code>public function generalSettings(){
  
  
      $totalprijs = 0;
      foreach($_SESSION['items'] as $key =&gt; $value){
          $products-&gt;setProduct($key);
          $totalprijs = $totalprijs + ($products-&gt;prijs_exBTW * $value);
      }
  
  
      $inclbtw = ($totalprijs * ('1.'.$this-&gt;BTWPercnt));
      if($totalprijs &gt; $this-&gt;franco_vanaf){
          $verzendkosten = 0;
      }else{
          $verzendkosten = $this-&gt;verzendkosten;
      }
  
      $btw = ($totalprijs + $verzendkosten) * ('0.'.$this-&gt;BTWPercnt);
  
      if($totalprijs &gt; $this-&gt;franco_vanaf){
          $totaalInc = ($totalprijs + $btw);
      }else{
          $totaalInc = ($totalprijs + $btw + $this-&gt;verzendkosten);
      }
  
      $return = array(
          "subtotaal" =&gt; $totalprijs,
          "btw" =&gt; $btw, 
          "inclbtw" =&gt; $inclbtw,
          "verzendkosten" =&gt; $verzendkosten,
          "totaalInc" =&gt; $totaalInc
      );
      return($return);    
  }
  </code></pre>
  
  <p>When I access this function from within the class it works. 
  <br>And when I call other function that uses this function in my checkout it works. </p>
  
  <p>But when I try to access it in my AJAX-handling file it says:</p>
  
  <p><code>Warning: Invalid argument supplied for foreach()</code></p>
  
  <p>The code,when I call the function in the ajax file is as below:</p>
  
  <pre><code>if($isValid == true){
      unset($notneeded);
      $notneeded = array("ww1","ww2","huisnr","vhuis","companyvat","companyname","tel","firstname","lastname");
      foreach($_POST['gegevens'] as $key =&gt; $value){
          if(in_array($key,$verplichtArray) &amp;&amp; (!in_array($key,$notneeded))){ 
              $fields .= "`".$key."`,";
              $values .= "'".$value."',";
          }
      }
      $shoppingcar = new Winkelwagen;
      $order = $shoppingcar-&gt;generalSettings();
  
      $fields .= '`timestamp`,`klant`,`totaal`,`totaalInc`,`verzendkosten`,`status`,`betaalmethode`';
      $values .= "now(),'".$acc-&gt;id."','".$order['subtotaal']."','".$order['totaalInc']."','".$order['verzendkosten']."','3','".mysql_real_escape_string($_POST['betaalwijze'])."'";
  
      if(isset($_POST['gegevens']['V'])){
          $fields .= ',`V`';
          $values .= ",'X'";
      }
  
      $message = "INSERT INTO order (".$fields.") VALUES (".$values.")";
  }
  </code></pre>
  
  <p>It seems like when I call the function from the ajax file the session's empty 
  but when I call the function from the file where I call to the ajax file it works just fine. </p>
  
  <p>Could anyone explain what I'm doing wrong??? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The piece of jquery i use to call the ajax file as requested:</p>
  
  <pre><code>$('#afrekenen').click(function(){
              clearInterval(myInterval);
              var fields = $('.addressform :input');
              $.each(fields, function(field,val){
                  $(val).removeClass('errorInput');
              })
              var gegevens = {};
              var adresform = $('.addressform').serializeArray();
              $.each(adresform, function(index, val){
                  gegevens[this.name] = this.value;
              });
              if(!$('input[name=payment]:checked').val()){
                  var betaalwijze = 0;
              }else{
                  var betaalwijze = $('.betaalwijze').val();
              }
  
              var voorwaarden = $('input[name=voorwaarden]:checked').val();
  
              $.ajax({
                  type: 'post',
                  url: '/inc/afrekenen.php',
                  data: {"gegevens":gegevens ,"betaalwijze":betaalwijze,"voorwaarden":voorwaarden},
                  success: function(data) {
                      response = jQuery.parseJSON(data)
                      if(response.isValid == false){
  
                          $('#errormsg').html('&lt;div class="alert alert-danger"&gt;'+
                          '&lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;'
                          +response.message+'&lt;/div&gt;');
  
                          $.each(response.fouteVelden, function(index, object){
                              $('#'+object+'').addClass('errorInput');
                          });
                      }else{
                          $('#errormsg').html('&lt;div class="alert alert-success"&gt;'+
                          '&lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;'
                          +response.message+'&lt;/div&gt;');
                      }
                  }
              });
      }); 
  </code></pre>
  
  <p>if have the 
  ob_start(); tag and the session_start(); tag</p>
  
  <p>also only the sessions that are somehow linked to my class are returning 1 when i try to print_r them the rest of my sessions still remain</p>
  
  <p>the foreach through the $_SESSION['item'] in the first part of my code isn't working 
  all the other parts of code work</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>A good nights sleep seems to have solved the conflict... 
  don't know what the error was and don't know how i fixed it but it works! 
  Thank you for the suggestions :)</p>