6

I know this is discussed already many times, but I think this is different case.

I am making a simple ajax call to a php method which is as below:

public function updateAbout()
{
    log_message('debug', "updateAbout is called", false);   

     log_message('debug',$this->input->post('fname'), false);

   log_message('debug', "updateAbout success", false);   

}

In this method I am simply trying to get data which is passed by ajax call.

But I don't get data posted by ajax call instead get 2 errors:

Severity: Warning --> session_start(): Cannot send session cache limiter - headers already sent ...\..\\libraries\Session\Session.php 143
Severity: Warning --> Cannot modify header information - headers already sent ..\..\libraries\Session\Session.php 171

Note:

I am not using session_start() anywhere in my project.

This error is pointing to session_start() method which is in Session.php file of CodeIgniter libraries. It is not pointing to anywhere in my code so I am not sure where do I look for issues.

I have already checked answers all over internet and none of them seem to solve this issue.

Why am I getting this error and how can I prevent this?

Edit:

As per suggestions in other answers, I have checked and removed spaces in <?php ?> in all my codes.

Here is my JavaScript code where ajx call is made.

      $("#btnupdateAbout").click(function(){

      $fname=$("#updatefname").val();
      $lname=$("#updatelname").val();
      $country=$("#updatecountry").val();
      $locality=$("#updatelocality").val();

      if($('#optradioMale').is(':checked')) { $gender="Male"; }
      else{$gender="Female";}

       $.ajax({

           url:"http://localhost/Voyager/ProfileControls/updateAbout",
           data:{'fname':$fname,'lname':$lname,'country':$country,'locality':$locality,'gender':$gender},
           method:"POST",
           contentType:false,
           cache:false,
           processData:false,

           success:function(){

           }

       });
   });
halfer
  • 19,824
  • 17
  • 99
  • 186
Dheeraj Kumar
  • 3,917
  • 8
  • 43
  • 80

3 Answers3

2

Could you please check this answer How to fix "Headers already sent" error in PHP

Probably, there is some output/or error thrown before the header is set.

Community
  • 1
  • 1
prab
  • 290
  • 1
  • 12
  • I don't get it. I mean I have nowhere echo statement printing anything, no session_start code, no whitespaces. Where do I look for. Error message is pointing to session library of codeigniter. :( – Dheeraj Kumar May 19 '17 at 12:23
1

Make use of F12 in your browser during the ajax call and and click on console and network to see your ajax call details, sometimes an error occur due to deprecated methods and you need to change some php settings in php.ini like

always_populate_raw_post_data = -1

also if you are using routes.php make sure you are using the correct path

Nassim
  • 2,879
  • 2
  • 37
  • 39
  • after few debugging we found out that issue was with url in ajax call which didnt match with actual url (Case sensitivity). Thanks a lot Nissam. – Dheeraj Kumar May 22 '17 at 08:26
0

When you make the AJAX call, you are calling the Code-igniter entry point which will load all the required libraries including starting the session.

Don't know what the function log_message() is doing, but I believe that tries to print to STDOUT and then later one your code or Code Igniter tries to send some Headers.

Can you post most details about your log_message() function???