用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2765|回复: 4
收起左侧

[HELP] 求CI用ajax的例子

[复制链接]
发表于 2014-4-28 18:41:59 | 显示全部楼层 |阅读模式
好像都没怎么找到类似的东西,有人能提供点例子给学习下吗?
发表于 2014-9-24 09:29:18 | 显示全部楼层
首先我先聲明,自己對 ajax 也不是很懂
最近的一個案子,剛好會應用到這塊,所以也還在學
但是 google 一下應該有不少資料可以看吧...關鍵字" ajax codeigniter "

我覺得這個例子就不錯:

http://runnable.com/UXczcazDrMMi ... codeigniter-for-php

/controllers/welcome1.php
PHP复制代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Welcome1 extends CI_Controller {
        public function index(){
                $this->load->view('form-view');
        }
}
复制代码


/controllers/time.php
PHP复制代码
<?php
class Time extends CI_Controller {
  public function index(){
          echo time();
  }
}
复制代码


/views/form-view.php
HTML复制代码
<html>
<head>
  <title> Ajax Exmaples! </title>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
  <script>
    $( document ).ready(function () {
      $("#button").click(function () {
        $.get("time", function (time) {
          $("#text").html("Time on the server is:" + time);
        });
      });
    });
  </script>
</head>
<body>
  <h1> Get Data from Server over Ajax </h1>
  <textarea id="text" readonly></textarea>
  <br/>
  <button id="button">Get Time from Server</button>
</body>
</html>
 
复制代码
发表于 2014-10-28 20:18:38 | 显示全部楼层
Closer 发表于 2014-9-24 09:29
首先我先聲明,自己對 ajax 也不是很懂
最近的一個案子,剛好會應用到這塊,所以也還在學
但是 google 一下 ...

您好,请问视图form-view.php里,哪段代码调用了time控制器?{:soso_e100:}
发表于 2014-10-29 09:12:59 | 显示全部楼层
$.get("time", function (time) {
发表于 2014-11-3 14:25:27 | 显示全部楼层
Closer 发表于 2014-10-29 09:12
$.get("time", function (time) {

哦,惭愧,得回去补补ajax知识了,十分感谢{:soso_e100:}

本版积分规则