codeigniter在jquery中无法正确调用控制器函数

时间:2014-09-22 16:42:16

标签: javascript php jquery html codeigniter

我创建了一个带有按钮的简单网页,点击此按钮我想通过在当前发票中加载页面来更改页面的这一部分。我写的代码如下:

带按钮的索引:

   <!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <link rel="icon" href="../../favicon.ico">

        <title>Justified Nav Template for Bootstrap</title>

        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

        <!-- Optional theme -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

        <!-- Latest compiled and minified JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

        <!-- Custom styles for this template -->
        <link href="http://getbootstrap.com/examples/justified-nav/justified-nav.css" rel="stylesheet">

        <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
        <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
        <script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script>

        <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
        <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>



        <script>
            $(document).ready(function() {
                /*
                 * ACCETTAZIONE
                 */
                $("#ricoveraPaziente").click(function() {
                    alert("adassdaasdasdsd");
                    $('#quiiiiii').load('fatture/index');
                    //e.preventDefault();


                });


            });
        </script>
    </head>

    <body>

        <div class="container">

            <div class="masthead">
                <h3 class="text-muted">Project name</h3>
                <ul class="nav nav-justified">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#" id="ricoveraPaziente">Projects</a></li>
                    <li><a href="#">Services</a></li>
                    <li><a href="#">Downloads</a></li>
                    <li><a href="#">About</a></li>
                    <li><a href="#">Contact</a></li>
                </ul>
            </div>
            <div id="quiiiiii">

                <!-- Jumbotron -->
                <div class="jumbotron">
                    <h1>Marketing stuff!</h1>
                    <p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet.</p>
                    <p><a class="btn btn-lg btn-success" href="#" role="button">Get started today</a></p>
                </div>

                <!-- Example row of columns -->
                <div class="row">
                    <div class="col-lg-4">
                        <h2>Safari bug warning!</h2>
                        <p class="text-danger">As of v7.0.1, Safari exhibits a bug in which resizing your browser horizontally causes rendering errors in the justified nav that are cleared upon refreshing.</p>
                        <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
                        <p><a class="btn btn-primary" href="#" role="button">View details &raquo;</a></p>
                    </div>
                    <div class="col-lg-4">
                        <h2>Heading</h2>
                        <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
                        <p><a class="btn btn-primary" href="#" role="button">View details &raquo;</a></p>
                    </div>
                    <div class="col-lg-4">
                        <h2>Heading</h2>
                        <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa.</p>
                        <p><a class="btn btn-primary" href="#" role="button">View details &raquo;</a></p>
                    </div>
                </div>

                <!-- Site footer -->
                <div class="footer">
                    <p>&copy; Company 2014</p>
                </div>

            </div> <!-- /container -->

        </div>
        <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
        <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
    </body>
</html>

调用片段JQuery的控制器是:

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Fatture extends CI_Controller {

    public function index()
    {
        $this->load->view('fatture');
    }
}

当我点击按钮时,codeigniter不会让我出现任何页面,我该如何解决?拜托:D

1 个答案:

答案 0 :(得分:0)

试试这个:

$("#ricoveraPaziente").click(function() {
    alert("adassdaasdasdsd");
    $.ajax({
        url: 'fatture/index',
        success: function(result){
            $('#quiiiiii').html(result);
        }
    });
});