Codeigniter与ajax警告wampserver主页

时间:2013-08-01 08:32:53

标签: codeigniter jquery wampserver

我是codeigniter的新手,我正在尝试一些ajax功能。关注ajax-codeigniter,我的观点是

<?php
$set_price_range_500_1500 = array(
    "name"=>"price_range",
    "value" => "500-1500",
    "id" => "pr_500_1500"
    );
?>
<?php echo form_checkbox($set_price_range_500_1500); ?>
<?php echo lang('price_range_500_1500'); ?> 

jquery位于ci\themes\default\assets\js\

 $(document).ready(function(){
    $("#pr_500_1500").click(function(){
        var range = $("pr_500_1500").val();

        $.post(
               '/index.php/ajax/getPricerangeProducts',
               {'range' : range },

               function( result )
               {
                    if( result )
                    {
                        alert( result ) ;   
                    }
               }
               );
    });
});

控制器ajax驻留在ci\controllers\

<?php
class ajax extends CI_Controller
{
    function __construct()
    {
        parent::__contruct();
    }

    function getPricerangeProducts()
    {
        echo 'hello';
    }
}

但它不会提醒hello,而是提醒wampserver主页!

1 个答案:

答案 0 :(得分:0)

更改此设置并尝试:

$.post(
'<?=base_url()?>/index.php/ajax/getPricerangeProducts',
{'range' : range },

function( result )
{
    if( result )
    {
        alert( result ) ;   
    }
}
);