简体   繁体   中英

Sending post data from Joomla to CodeIgniter

I have a system implemented in CodeIgniter, I am trying to send some data in a text area of Rsform component via POST to the url referring to my CodeIgniter system, I have tried usign AJAX request to send the post data using the following code

<script>
alert("jsc");
  var data;
  data='test from joomla!';
      $.ajax({
                type: "POST",
                url : 'http://localhost/cii/index.php/login/getNews/',
                data: {news:data},
                cache: false,

                success: function(html){
                alert(html);
                }
            });

getNews controller:

function getNews() {
  //print_r($this->session->userdata);
  header('Access-Control-Allow-Origin: *');
  echo "news is ".$news=$_POST['news'];
  $data = array ( 'username' => "null", 'is_logged_in' => false, 'news'=>$news);
  $this->session->set_userdata($data); //var_dump($_POST); //               
  print_r($this->session->userdata); session_start(); echo session_id(); 
} 

but it failed, is there any other options ?

Use something like Firebug in mozilla firefox to observe what data is being posted to the app to check if your ajax call is working.

Then in your codeigniter controller method, simply put this code to see if the data is getting to it.

function getNews()
{  
    foreach($_POST as $key => $val)  
    {  
        $options[$key] = $this->input->post($key);  
    }  

    var_dump($options);      
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM