Hi, I am developing an Android application (use phonegap, html5 and javascript) that connect to the remote mysql database. I created a RESTful web service (codeigniter) to access the mysql database, then the Android application can call the web service to receive or send data in db using XML or JSON as the data format.
In a web browser using jquery ajax, I successfully get the result, but in the Android app I don't get the answer.
jQuery.ajax({
url : 'http://10.10.1.129/index.php/apiauth/auth/?'+jQuery("#form-login").serialize(),
async :true,
cache :false,
dataType : 'jsonp',
success:function(data){
alert(data);
}
});
on server:
require APPPATH.'/libraries/REST_Controller.php';
class Apiauth extends REST_Controller
{
function auth_get()
{
$this->load->model('mauth');
$username = $this->input->get('username') ? $this->input->get('username') : $this->get('username');
$password = $this->input->get('password') ? $this->input->get('password') : $this->get('password');
$auth = $this->mauth->getUserLogin('*',$username,$password);
$row = $auth->row();
if($row){
$data = array('username'=>$row->username, 'fullname'=>$row->fullname,'error'=>FALSE);
}else{
$data = array('error'=>true);
}
$this->response($data, 200);
}
source
share