Q:

While sending json data in ajax gives an error like Unexpected token :

I am creating login with facebook application in codeigniter. So, I want to pass json data into my controller using ajax.
Here my code is like : 
var data = JSON.stringify(response);
   alert(data);
   $.ajax(function(){
     type:"post",
     //contentType: 'application/json',
     //dataType: 'json',
     url:"<?php echo base_url().'login/insert_fb' ?>",
     data:{email:email,id:id}
   }).done(function(data){
        alert(data);
   });

Here, In my login controller I have written code like this : 
function insert_fb()
{       
    $data = json_decode($this->input->post($response));
    print_r($data);
}

Here, In data variable i got all json record.But when I call ajax function then it gives an error like Unexpected token :.
So, how can I resolve this problem?
Note : If I remove method and dataType and contentType then it gives an error like Unexpected token : at url.

A:

You have to remove function() from your ajax:
var data = JSON.stringify(response);
   alert(data);
   $.ajax({
     type:"post",
     //contentType: 'application/json',
     //dataType: 'json',
     url:"<?php echo base_url().'login/insert_fb' ?>",
     data:{email:email,id:id}
   }).done(function(data){
        alert(data);
   });

