在Codeigniter中的Ajax上获取error404 [英] Getting error404 on Ajax in Codeigniter

查看:134
本文介绍了在Codeigniter中的Ajax上获取error404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的ajax代码的问题。我试图增加数字内部跨越点击与ajax,但不断得到错误控制台 - POST localhost / slots / game / lines 404(找不到)。 Btw,我使用Codeigniter。

I have problem with my ajax code. I`m trying to increase number inside span on click with ajax, but keep getting error in console - POST localhost/slots/game/lines 404 (Not Found) . Btw, I use Codeigniter.

以下是代码:

PHP b
$ b

PHP (Controller)

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Game extends CI_Controller {
    function __construct()
    {
        parent::__construct();
    }
    function index(){
    }
    function win()
    {
        $this->session->set_userdata( array('win') => $win);
        $win = $this->input->post('win');
    }
    function lines()
    {
        $this->session->set_userdata( array('lines') => $lines);
        $lines = $this->input->post('lines');
        echo $lines++;
    }
    function wager(){
        $this->session->set_userdata( array('wager') => $wager);
        $wager = $this->input->post('wager');
    }   
}
?> 

这里是我的Ajax -

And here is my Ajax -

function lines()
{
var lines = parseInt($('#lines span').html()) + 1;
$.ajax({
        type: 'POST',
        url: base_url + 'game/lines',
        data: { lines: lines },
        success:function(response){
            if(response <= 8){
                $('#lines span').html(response);
                return true;
            }
            else return false;
        }

});
}

在我的HTML中,我调用 lines function onclick .I'm使用最新的xampp作为我的虚拟主机。我也有一个自定义路由在CI -

And in my HTML I call lines function onclick.I`m using latest xampp as my virtual host.I also have one custom route in CI -

$route['game/(:any)'] = "game/$1";


PS base_url在JS中定义为变量。

P.S. base_url is defined in JS as variable.

推荐答案

正如我们在注释中发现的,你的问题是url_rewrite。请尝试以下操作:

As we found out in the comments your problem is the url_rewrite. Try this:

创建一个名为.htaccess的文件,并将其放在根文件夹中,您的index.php文件是(注意前面的点)。编写此代码:

Make a file called .htaccess and place it in root folder, where your index.php file is (notice the dot in front). Write this code:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

在application / config / config.php中,索引文件选项应该是空的,如:

In application/config/config.php the index file option should be empty empty like:

$config['index_page'] = '';

这篇关于在Codeigniter中的Ajax上获取error404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆