weixin_33724659 2015-02-25 05:45 采纳率: 0%
浏览 18

无法在ci中传递数据ajax

$("body").on('click', '.name', function(e) {
   //var valueofbutton = $(this).val();         
            $.ajax({
     type: "POST",
     url: "response",
     data: "name=John&location=Boston",
     success: function(msg){
        alert( "Data Saved: " + msg );
     }
});

});

my response controller

Class Response extends CI_Controller{


public function index()
{

$data=$this->input->post('name'); 

echo $data;

}


}

it shows me some errors i dont know what kind of error is it !

my alert gives this information

Data Saved: <br />
<b>Warning</b>:  Unterminated comment starting line 25 in <b>C:\xampp\htdocs\vacationgod\application\controllersesponse.php</b> on line <b>25</b><br />
John

and i cant see any print information like john which i pass to response controller

  • 写回答

2条回答 默认 最新

  • weixin_33739646 2015-02-25 06:45
    关注

    Your data should be an object and remove .name. change that line in you ajax like this:

    $("body").on('click', function(e) {
      $.ajax({
        type: "POST",
        url: "response.php",
        data: {name: "John",location:"Boston"},
        success: function(msg) {
          alert("Data Saved: " + msg);
        }
      });
    });
    
    评论

报告相同问题?