所以我越來越好使用phonegap,但我仍然試圖完全添加codeigniter作爲後端。我已經能夠在jQuery中加載一些東西,從我的CI控制器到我的phonegap android應用程序,但似乎無法正確提交任何內容到服務器。你需要一個休息服務器從手機通信與CI?我打算使用ajax post來向CI發送信息,但至今無法使其工作。我真的很感激有人可以幫助我渡過這個障礙。由於phonegap與codeigniter後端
控制器:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
//$this->load->view('welcome_message');
$data['query']=$this->site_model->get_last_ten_articles();
$this->load->view('partial1',$data);
}
public function addarticle(){
$headline=$this->input->post('headline');
$article=$this->input->post('article');
$this->site_model->insert_entry($headline,$article);
}
}
的Javascript(PhoneGap的設備上)
function add_article(){
$.ajax({
type: 'POST',
url: 'http://testlab.site40.net/droiddev/welcome/addarticle/',
data: {"headline": "test headline","article": "test article"}
error: function(){alert('fail');},
success: function(data){
alert('article added');
},
dataType: "json"
});
}
顯示您編寫的代碼無法與codeigniter後端進行成功通信。這是在模擬器還是在設備上? – Femi
將profiler添加到你的'add_article'類中:'$ this-> output-> enable_profiler(TRUE);'它會輸出所有捕獲的數據(POST等等)它可能只是輸入了一些東西,是你的朋友! – Jakub
@Jakub感謝探查器技巧!完全忘了。它是有用的:) –