category: codeigniter

Codeigniter - Note

on 2013-09-02

Something about CI note

user guide

redirect

$this->load->helper('url');

Codeigniter - AJAX(post)

on 2013-08-29

CI AJAX(Post)

Usage

JavaScript(jQuery)

$.post(
    '/api/post',
    {
        val: 'string',
        val2: 1
    },
    function(data) {
        console.log(data);
        if(data.status === 'ok') {
            // dosomething
        } else {
            // alert fail
        }
    },
    'json'
);
$.ajax({
  url: '/login/signup',
  type: 'POST',
  data: {
  	account: $('input[name="account"]').val()
  },
  success: function(data) {
  	console.log(data);
  }
});

PHP

<?php

// api.php
public function post()
{
    $val = $this->input->post('val');
    $val2 = $this->input->post('val2');

    if ($val)
    {
        // dosomething

        //response
        $output = array(
            'status' => 'ok',
            'msg' => 'success'
        );
        echo json_encode($output);
        exit;
    }
    $output = array(
        'status' => 'fail',
        'msg' => 'error'
    );
    echo json_encode($output);
    exit;
}

?>

Read more