I'm trying to send data from a phonegap mobile app to my server using $.ajax
method
I use this code :
var form_data = {parm: 1, token: "2fa7e7e5e76005ffd8bfa5082da9f2f9"};
$.ajax({
url: "http://example.com/index.php/register_devices/register/format/json",
type: 'POST',
data: form_data,
//dataType:"jsonp",
success: function(data){
alert(data);
},
error: function(xhr, textStatus, errorThrown){
alert('request failed: '+ errorThrown);
}
});
return false;
I also put this line in my config.xml file :
<access origin="*" />
And in the server side I use codeigniter
framework with RESTful
library like this code :
require(APPPATH.'/libraries/REST_Controller.php');
class Register_devices extends REST_Controller {
public function register_post()
{
$parm = $this->input->post('parm');
$token = $this->input->post('token');
echo $token;
}
}
when I use GET
method it works successfully but the problem is when I use POST
method I receive :
"internal server error"
.. Any solve ?
The problem was because this config option :
$config['csrf_protection'] = FALSE;
I just put it FALSE
and it works prefect .