Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6697691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:29:23+00:00 2026-05-26T06:29:23+00:00

So I am getting better at using phonegap but am still trying to fully

  • 0

So I am getting better at using phonegap but am still trying to fully add codeigniter as the backend. I have been able to .load in jquery something from a controller of my CI to my phonegap android app but can’t seem to submit anything TO the server properly. Do you need a rest server to communicate with CI from phonegap? I was planning on using ajax post to info to CI but so far unable to get it to work. I’d really appreciate it someone can help me over this hurdle. Thanks

link 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 phonegap 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"
});

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:29:24+00:00Added an answer on May 26, 2026 at 6:29 am

    First of all, lets get your example running, your post data is json, and the datatype is json but your CI implementation is accessing post variables.

    The quick and dirty fix is to submit a uri string in the post data such as:

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

    This can be generated from a form with the jquery serialize function:

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

    This post data will be set in the $_POST var on submission and then later accessible through the CI post function:

    $this->input->post()

    *Note: remeber to remove the dataType setting in the ajax call for this to work.

    For a more politically correct way to solve this problem, you’re going to want to leave your javascript alone (thats all good) but you need to set the CI backend up as a RESTful service, the default installed controller and input classes won’t handle it. You need to use something like Phil Sturgeon’s REST implementation:

    • There is a github project for the code,
    • A blog post (read this first – its a good short primer on REST servers for CI concerned usage),
    • And the tutorial you already know about.
    • Oh and a video on setting it up.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting better at regex, but I'm still having some trouble... I'm trying to
I am trying to work on getting better at making HTML forms using PHP
I'm getting familiar with objC, but I'm still confused as to when using C
Quick one, but thought I'd ask. Is there a better way of getting the
First off, fairly new to JS but getting better :-) This question is similar
I have been using Grails for the past few months and I really like
I am using free-text on my website to get better search results but am
I'm having a hard time getting better results on this query: I have the
I am an Objective-C newbie, who still does not have a Mac, but still
Possible Duplicate: Learning jQuery and Getting Better at Javascript I have found jQuery very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.