Telephone delay with codeigniter base code

So, I am improving the use of phonegap, but I'm still trying to completely add codeigniter as a backend. I was able to load something from my CI controller into jQuery into the Android phone phone application, but it seems I can’t imagine anything on the server. Do you need a leisure server to communicate with CI from a phone saver? I planned to use the ajax message for information in CI, but so far I have not been able to get it to work. I would really appreciate that someone can help me overcome this obstacle. Thanks

reference to relative answer

Controller:

<?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 (on a phone device)

 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" }); } 
+4
source share
1 answer

First of all, let's try running your example, your mail data is json and the data type is json, but your CI implementation has access to post variables.

A quick and dirty fix is ​​to send the uri string to the message data, for example:

&headline=test%20headline&article=test%20article

This can be generated from the form using the jquery serialization function:

var myData = $('#form-id').serialize();

This post data will be set to $ _POST var upon presentation, and then later accessible through the CI column function:

$this->input->post()

* Note: remember to remove the dataType parameter in the ajax call for this.

For a more politically correct solution to this problem, you will want to leave your javascript alone (all is good), but you need to configure the CI backend as a RESTful service, the default controller and input classes will not cope with this. You need to use something like Phil Sturgeon REST implementation:

  • There is a github project for code,
  • A blog post (read this first - this is a good short tutorial on REST servers for using CI)
  • And the tutorial that you already know about.
  • Oh and video when setting up.
+6
source

All Articles