【问题标题】:how to call a codeigniter function from jquery ajax如何从 jquery ajax 调用 codeigniter 函数
【发布时间】:2013-07-11 18:23:48
【问题描述】:

我正在使用 https://code.google.com/p/jquery-datatables-editable/wiki/EditCell#Client-side_configuration 的 jquery-datatables-editable 插件和 CI。我有:

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
       $('#myDataTable').dataTable().makeEditable({
           sUpdateURL: "/js/jquery-databatables-editable/AjaxUpdate_1.php/index"
       });
    });
 </script>

在客户端页面上。我希望能够在服务器端向一个类发布 CI 库类/函数,但上述方法似乎不起作用。有没有办法做到这一点?

【问题讨论】:

标签: php javascript jquery codeigniter datatables


【解决方案1】:

这取决于您的配置。

大多数情况下,如果您使用默认设置:

在您的 Javascript 文件或视图中(如果是内联的)

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
       $('#myDataTable').dataTable().makeEditable({
           sUpdateURL: "/index.php/your_controller/function_name"
       });
    });
 </script>

在你的 routes.php 中

$route["function_name"] = "your_controller/function_name/";

最后,您需要在控制器中创建一个函数并输出预期的格式:

function function_name(){
    echo json_encode('whatever you need to return');
}

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    相关资源
    最近更新 更多